I’ve had just some time to do some performance test and compare different languages. I’ve created scripts in each language which does the following:
for 1’000’000 lines
“line” is empty
for 150 chars
add char “c” to the “line”
print out the “line”
Running the script and pipe the output to a file creates a 145MB file. And the most interesting result is the time each script took to run:
Shell$ time python createRandomFile.py --rows 1000000 --chars 150 > bigfile.py.txt real 0m56.207s user 0m55.348s sys 0m0.607s
Shell$ time perl createRandomFile.pl -r 1000000 -c 150 > bigfile.pl.txt real 0m37.742s user 0m37.147s sys 0m0.488s
Shell$ time php createRandomFile.php -r 1000000 -c 150 > bigfile.php.txt real 1m9.357s user 1m5.165s sys 0m3.542s
Shell$ time java createRandomFile 1000000 150 > bigfile.java.txt real 1m18.791s user 1m0.689s sys 0m11.133s
Shell$ time ruby createRandomFile.rb -r 1000000 -c 150 > bigfile.ruby.txt real 1m44.118s user 1m39.672s sys 0m0.967s
Shell$ time ruby createRandomFile.sh 1000000 150 > bigfile.bash.txt real 78m46.334s user 56m30.018s sys 3m5.280s
Shell$ time ./createRandmonFile -r 1000000 -c 150 > bigfile.c.txt real 0m2.159s user 0m1.339s sys 0m0.425s
For me personally there are some unexpected new experiences:
- Python takes “much” longer than perl. After performance optimizing the Python script its much faster, but still slower than the perl script. Thats really sad…
- Not a big surprise is the fact, that the C program is the fastest. But that it is so much faster than all others is impressive.
- Using echo instead print in the php script gets the script one second faster.
- And the fact, java is one of the most slowest language of all competitors used here.
- Ruby is damn slow
- Finally, Bash IS the slowest… Damn slow! I mean, SLOOOWWW!!!
This are really interesting results!
Tagged: Bash, c, Java, performance, Perl, PHP, python, Ruby




