I love Perl – and the perl interpreter always impresses me. Today, I decided to try a few languages to see how they compare.
How well does the language do nothing? I decided to test this out on my fairly speedy Macbook Pro. All tests were executed multiple times and the best result was used for this post, to account for various caching speedups.
First, C:
do-nothing$ touch nothing.c do-nothing$ time clang nothing.c Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) real 0m0.041s user 0m0.017s sys 0m0.017s
So, C can spit out an error that will probably not make sense to people new to the language (it’s missing a main function, although usually you’ll define main without a leading underscore – for reasons I won’t get into here). But it was fairly quick – about 40ms (I repeated this several times to account for caching).
Next I tried Java (using the SunOracle implementation):
do-nothing$ touch nothing.java do-nothing$ time javac nothing.java real 0m0.759s user 0m1.323s sys 0m0.105s
Java doesn’t throw any errors, but it takes over 750ms to compile nothing (in a somewhat satisfyingly mathematically pure way, it literally produces nothing – no output files are created). When I ran javac with the -verbose option (how a Unix workstation company would think long options with a single hypen are okay is beyond me, but I digress), it spits out some timing information. It takes 23ms to parse nothing and roughly 290ms to do the compilation. I can only assume the other 450ms or so are going to compiler startup overhead.
How about Ruby?
do-nothing$ touch nothing.rb do-nothing$ time ruby nothing.rb real 0m0.073s user 0m0.053s sys 0m0.010s do-nothing$
It takes 73ms to do nothing, but it does properly do nothing.
How about Python (v2)?
do-nothing:t$ touch nothing.py do-nothing:t$ time python nothing.py real 0m0.018s user 0m0.009s sys 0m0.007s
Python does nothing pretty darn well – 18ms!
Now, my language of choice, Perl 5:
do-nothing$ touch nothing.pl do-nothing$ time perl nothing.pl real 0m0.006s user 0m0.002s sys 0m0.003s do-nothing$
Brilliant – it does nothing very quickly compared to other languages – 6ms.
That said, my old version (Christmas) of the Rokudo-based Perl 6 takes roughly 250ms – not all that good. I’m not sure how the newer versions do. It’s certainly a powerful new language (you should think of Perl 5 and Perl 6 as distinct language – both are being actively developed with new features, optimizations, bug fixes, etc, added to both continually, with no plans to discontinue development on either).
So, It think, in conclusion:
- C isn’t good for nothing
- Java can’t do nothing quickly
- Perl 6 can do nothing, but not too quickly
- Ruby seems okay for nothing, while Python 2 is pretty darn good at nothing
- Perl 5 is good for nothing!
(Yes, this post is 90% jest – startup time of the tools is important, but is almost always a dumb reason to pick a language)
Pingback: Making PAR::Packer Work with RPM | Digital Barbed Wire
I got Perl 6, version 2018.09-453, and made a nothing.pl with nothing in it and did a time perl6 nothing.pl:
real 0m0.153s
user 0m0.164s
sys 0m0.016s
That’s a lot better than your 250ms. It’s still not good. But when somebody is going to spend some valuable time on the startup process, there is a lot to be gained. It is not going to be easy though…
LikeLike
What makes you believe one can “measure” C startup perfomance this way?
The very Perl interpreter (same for Python, Ruby, etc and probably the C
compiler itself) is written in C! In all this cases you “measured” C’s startup
time aswell. 😉
C is not an interpreted language, so compiling and running are 2 different
steps. All you measured here is the C compiler’s startup time which might
be quite high indeed, similar holds for Java.
Do this instead:
$ echo ‘int main ( void ) { return 0 ; }’ > nothing.c
and now compile it:
$ gcc -O2 -s nothing.c
There you go:
$ time [-p] ./a.out
How does this compare?
How fast is “doing nothing” in C really?
Maybe the other scripting languages can also speed up by
reducing the libraries they might suck in at startup, I dunno.
LikeLike
Pingback: Perl Weekly Challenge 13 Task 1 – Smallest Script | Digital Barbed Wire