Tuesday, June 1, 2010

Java "Hello, World!" 6x slower than Python

Yup. I know, micro-benchmarks, but I find this one quite interesting. Take two small programs, one Java, one Python:

package com.test; public class TestJava { public static void main(String[] args) throws Exception { System.out.println("Hello, World!"); } } print "Hello, World!"

Running these two through time clearly shows that Java is 6 (six) times slower:

[felix@the-machine bin]$ time java com.test.TestJava Hello, World! real 0m0.142s user 0m0.080s sys 0m0.017s [felix@the-machine bin]$ time java com.test.TestJava Hello, World! real 0m0.142s user 0m0.077s sys 0m0.020s [felix@the-machine bin]$ time java com.test.TestJava Hello, World! real 0m0.154s user 0m0.070s sys 0m0.023s [felix@the-machine python]$ time python test.py Hello, World! real 0m0.024s user 0m0.013s sys 0m0.007s [felix@the-machine python]$ time python test.py Hello, World! real 0m0.025s user 0m0.020s sys 0m0.003s [felix@the-machine python]$ time python test.py Hello, World! real 0m0.026s user 0m0.013s sys 0m0.007s

Not only is Java slower, it's also a lot more code. And I'm not only talking about lines of code here (which, still, are 6 times more; really it's 1 line of Python and 6 of Java -- if you remove the whitespace), but compiled code, too. Look:

[felix@the-machine bin]$ ls -lh com/test/TestJava.class -rw-r--r-- 1 felix felix 595 Jun 1 21:50 com/test/TestJava.class [felix@the-machine python]$ ls -lh test.pyc -rw-r--r-- 1 felix felix 117 Jun 1 21:59 test.pyc

The compiled Java code is 595 bytes, while the compiled Python code is 117 bytes. Five times bigger. Say it with me: Java == BLOAT !

2 comments:

  1. If you're trying to lose fat then you need to jump on this totally brand new tailor-made keto diet.

    To create this keto diet service, licensed nutritionists, fitness couches, and professional cooks have united to provide keto meal plans that are useful, convenient, money-efficient, and fun.

    Since their launch in January 2019, 1000's of people have already transformed their body and well-being with the benefits a certified keto diet can give.

    Speaking of benefits: in this link, you'll discover 8 scientifically-confirmed ones given by the keto diet.

    ReplyDelete
  2. Compre documentos en línea, documentos originales y registrados.
    Acerca de Permisodeespana, algunos dicen que somos los solucionadores de problemas, mientras que otros se refieren a nosotros como vendedores de soluciones. Contamos con cientos de clientes satisfechos a nivel mundial. Hacemos documentos falsos autorizados y aprobados como Permiso de Residencia Español, DNI, Pasaporte Español y Licencia de Conducir Española. Somos los fabricantes y proveedores de primer nivel de estos documentos, reconocidos a nivel mundial.

    Comprar permiso de residencia,
    permiso de residenciareal y falso en línea,
    Compre licencia de conducir en línea,
    Compre una licencia de conducir española falsa en línea,
    Comprar tarjeta de identificación,
    Licencia de conducir real y falsa,
    Compre pasaporte real en línea,

    Visit Here fpr more information. :- https://permisodeespana.com/licencia-de-conducir-espanola/
    Address: 56 Guild Street, London, EC4A 3WU (UK)
    Email: contact@permisodeespana.com
    WhatsApp: +443455280186

    ReplyDelete