Showing posts with label lua. Show all posts
Showing posts with label lua. Show all posts

2015-02-26

Numeric CombSort Benchmark update!

As I've written before, CombSort are quite good sort algorithm. Let's compare this algorithm when implemented in various programming language. The benchmark should not use any other built-in function other than array generation and printing. The benchmark uses AMD A8-6600K, 16GB RAM with Non-SSD disk.

$ alias | grep 'alias time'
alias time='/usr/bin/time -f "\nCPU: %Us\tReal: %es\tRAM: %MKB"'
$ time --version
GNU time 1.7

g++ --version
g++ (GCC) 4.9.2 20141224 (prerelease)
$ time g++ comb.cpp
CPU: 0.05s      Real: 0.12s     RAM: 19428KB
$ time ./a.out
CPU: 1.94s      Real: 1.97s     RAM: 79804KB
$ time g++ -O2 comb.cpp
CPU: 0.07s      Real: 0.11s     RAM: 21260KB
$ time ./a.out
CPU: 0.88s      Real: 0.90s     RAM: 79804KB

clang --version
clang version 3.5.1 (tags/RELEASE_351/final)
$ time clang++ comb.cpp
CPU: 0.05s      Real: 0.08s     RAM: 33564KB
$ time ./a.out
CPU: 1.83s      Real: 1.86s     RAM: 79764KB
$ time clang++ -O2 comb.cpp
CPU: 0.08s      Real: 0.14s     RAM: 37860KB
$ time ./a.out
CPU: 0.89s      Real: 0.91s     RAM: 79804KB

java -version
java version "1.7.0_71" 
$ time javac comb.java
CPU: 1.05s      Real: 0.73s     RAM: 65952KB
$ time java comb
CPU: 1.32s      Real: 1.32s     RAM: 110488KB

php --version
PHP 5.6.4 (cli) (built: Dec 17 2014 21:45:04)
$ time php comb.php
CPU: 102.69s    Real: 104.20s   RAM: 2497508KB

hhvm --version
HipHop VM 3.5.0 (rel)
$ time hhvm -v Eval.Jit=true comb.php 
CPU: 12.56s     Real: 14.83s    RAM: 362488KB

ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
$ time ruby comb.rb
CPU: 52.87s     Real: 53.02s    RAM: 87892KB

rbx --version
rubinius 2.5.2 (2.1.0 7a5b05b1 2015-01-30 3.5.1 JI) [x86_64-linux-gnu]
$ time rbx comb.rb
CPU: 74.89s     Real: 74.30s    RAM: 135320KB

node --version
v0.10.35
$ time node comb1.js
CPU: 2.64s      Real: 2.64s     RAM: 92240KB
$ time node comb2.js
CPU: 2.68s      Real: 2.72s     RAM: 140612KB

rhino < /dev/null 
Rhino 1.7 release 4 2014 07 01
$ rhino comb2.js
CPU: 87.39s     Real: 61.16s    RAM: 1993848KB

$ pacman -Qo `which jsc-3`
/usr/bin/jsc-3 is owned by webkitgtk 2.4.8-1
$ time jsc-3 comb1.js
CPU: 23.74s     Real: 23.93s    RAM: 93740KB
$ time jsc-3 comb2.js
CPU: 18.99s     Real: 19.16s    RAM: 181644KB

js24 --help | grep Version
Version: JavaScript-C24.2.0
$ time js24 --ion-eager comb1.js
CPU: 2.13s      Real: 2.15s     RAM: 89688KB
$ time js24 --ion-eager comb2.js
CPU: 1.53s      Real: 1.58s     RAM: 92384KB

go version
go version go1.4.1 linux/amd64
$ time go build comb.go 
CPU: 0.14s      Real: 0.17s     RAM: 31568KB
$ time ./comb
CPU: 1.10s      Real: 1.14s     RAM: 79824KB

rustc --version
rustc 1.0.0-dev
$ time rustc comb.rs
CPU: 0.39s      Real: 0.49s     RAM: 106844KB
$ time ./comb
CPU: 10.62s     Real: 10.71s    RAM: 86020KB
$ time rustc -O comb.rs
CPU: 0.41s      Real: 0.49s     RAM: 110204KB
$ time ./comb
CPU: 0.97s      Real: 0.99s     RAM: 86108KB

scala -version
Scala code runner version 2.11.5 -- Copyright 2002-2013, LAMP/EPFL
$ time scala comb.scala
CPU: 5.43s      Real: 6.30s     RAM: 206088KB
$ time scalac comb.scala
CPU: 10.62s     Real: 7.00s     RAM: 143460KB
$ time scala Comb
CPU: 5.49s      Real: 5.05s     RAM: 206300KB

python --version
Python 3.4.2
$ time python comb1.py
CPU: 90.47s     Real: 90.83s    RAM: 403192KB
$ time python comb2.py
CPU: 106.82s    Real: 107.26s   RAM: 87248KB

pypy --version
Python 2.7.8 (c6ad44ecf5d8, Nov 18 2014, 18:04:31) [PyPy 2.4.0 with GCC 4.9.2]
$ time pypy comb1.py
CPU: 5.34s      Real: 5.40s     RAM: 136764KB
$ time pypy comb2.py
CPU: 5.85s      Real: 6.04s     RAM: 204588KB

mcs --version
Mono C# compiler version 3.12.0.0
$ time mcs -o+ comb.cs
CPU: 0.44s      Real: 0.47s     RAM: 45908KB
$ time ./comb.exe
CPU: 1.38s      Real: 1.41s     RAM: 90472KB

lua -v
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
$ time lua comb.lua
CPU: 65.64s     Real: 65.81s    RAM: 264096KB

luajit -v
LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall.
$ time luajit comb.lua
CPU: 6.30s      Real: 6.34s     RAM: 132964KB

dart --version
Dart VM version: 1.8.5 (Tue Jan 13 12:44:14 2015) on "linux_x64"
$ time dart scomb.dart
CPU: 2.12s      Real: 2.24s     RAM: 93392KB

The code can be found on my dropbox (folder: num-comb), and here's the summary:

Compiler / InterpreterLanguageCompile DurationCompile RAMRuntime DurationRuntime RAMTotal Duration
g++ (debug)C++50194281940798041990
g++ (-O2)C++702126088079804950
clang++ (debug)C++50335641830797641880
clang++ (-O2)C++803786089079804970
javac, javaJava10506595213201104882370
phpPHP1026902497508102690
hhvmPHP1256036248812560
rubyRuby528708789252870
rbxRuby7489013532074890
node (typed array)Javascript2640922402640
node (untyped array)Javascript26801406122680
rhino (untyped array)Javascript87039199384887039
jsc-3 (typed array)Javascript237409374023740
jsc-3 (untyped array)Javascript1899018164418990
js24 (typed array)Javascript2130896882130
js24 (untyped array)Javascript1530923841530
goGo140315681100798241240
rustc (debug)Rust390106844106208602011010
rustc (-O2)Rust410110204970861081380
scalaScala54302060885430
python3Python 39047040319290470
python3 (array)Python 310682087248106820
pypyPython 253401367645340
pypy (array)Python 258502045885850
mcsC#440459081380904721820
luaLua6564026409665640
luajitLua63001329646300
dartDart2120933922120

Write down your opinion (or pastie if you found a bug on these source, or if you want to add more language implementation) on the comment section ^^)b

Note #1Opal (0.6.8) and JRuby (both 1.7.18 and 9.0.0pre1) failed to run this benchmark (they exceed 300s runtime limit even when using -J-Xmx3000M -J-Djruby.compile.mode=FORCE flag).

Note #2: Yes, it's unfair to compare array of integer and array of double, life is unfair by design, get over it...

String CombSort Benchmark update!

Previously, we have benchmark CombSort algorithm implemented in various programming language for array of number. Let's compare this algorithm with addition integer to string conversion the language's built-in string library. The benchmark should not use any other built-in function other than string, integer conversion and array generation and printing. The benchmark uses AMD A8-6600K, 16GB RAM with Non-SSD disk.

$ alias | grep 'alias time'
alias time='/usr/bin/time -f "\nCPU: %Us\tReal: %es\tRAM: %MKB"'
$ time --version
GNU time 1.7

g++ --version
g++ (GCC) 4.9.2 20141224 (prerelease)
$ time g++ -std=c++11 scomb.cpp
CPU: 0.18s      Real: 0.20s     RAM: 35868KB
$ time ./a.out
CPU: 19.32s     Real: 19.60s    RAM: 548912KB
$ time g++ -std=c++11 -O2 scomb.cpp
CPU: 0.20s      Real: 0.24s     RAM: 38184KB
$ time ./a.out
CPU: 13.76s     Real: 14.05s    RAM: 548816KB

clang --version
clang version 3.5.1 (tags/RELEASE_351/final)
$ time clang++ -std=c++11 scomb.cpp
CPU: 0.15s      Real: 0.20s     RAM: 42240KB
$ time ./a.out
CPU: 18.89s     Real: 19.21s    RAM: 548868KB
$ time clang++ -std=c++11 -O2 scomb.cpp
CPU: 0.20s      Real: 0.23s     RAM: 45824KB
$ time ./a.out
CPU: 13.87s     Real: 14.15s    RAM: 548820KB

javac -version
javac 1.7.0_71
$ time javac scomb.java
CPU: 1.13s      Real: 0.80s     RAM: 65324KB
$ time java scomb
CPU: 48.96s     Real: 27.59s    RAM: 906652KB

hhvm --version
HipHop VM 3.5.0 (rel)
$ time hhvm -v Eval.Jit=true scomb.php
CPU: 89.92s     Real: 90.38s    RAM: 877468KB

ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
$ time ruby scomb.rb
CPU: 114.67s    Real: 115.21s   RAM: 870612KB

node --version
v0.10.35
$ time node scomb.js
CPU: 17.44s     Real: 17.41s    RAM: 411144KB

$ pacman -Qo `which jsc-3`
/usr/bin/jsc-3 is owned by webkitgtk 2.4.8-1
$ time jsc-3 scomb.js
CPU: 60.08s     Real: 43.66s    RAM: 834744KB

js24 --help | grep Version
Version: JavaScript-C24.2.0
$ time js24 scomb.js
CPU: 19.27s     Real: 19.62s    RAM: 735556KB

go version
go version go1.4.1 linux/amd64
$ time go build scomb.go
CPU: 0.14s      Real: 0.17s     RAM: 30428KB
$ time ./scomb
CPU: 11.45s     Real: 11.54s    RAM: 251628KB

scala -version
Scala code runner version 2.11.5 -- Copyright 2002-2013, LAMP/EPFL
$ time scala -J-Xmx3000M scomb.scala
CPU: 83.42s     Real: 46.10s    RAM: 1093924KB

python --version
Python 3.4.2
$ time python scomb.py
CPU: 121.33s    Real: 122.06s   RAM: 641844KB

pypy --version
Python 2.7.8 (c6ad44ecf5d8, Nov 18 2014, 18:04:31) [PyPy 2.4.0 with GCC 4.9.2]
$ time pypy scomb.py
CPU: 14.72s     Real: 14.97s    RAM: 522080KB

lua -v
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
$ time lua scomb.lua
CPU: 98.11s     Real: 98.54s    RAM: 863880KB

luajit -v
LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall.
$ time luajit scomb.lua
CPU: 21.30s     Real: 21.61s    RAM: 511268KB

dart --version
Dart VM version: 1.8.5 (Tue Jan 13 12:44:14 2015) on "linux_x64"
$ time dart scomb.dart
CPU: 11.92s     Real: 12.15s    RAM: 497788KB

The code can be found on my dropbox (folder: str-comb), and here's the summary:

Compiler / InterpreterLanguageCompile DurationCompile RAMRuntime DurationRuntime RAMTotal Duration
g++ (debug)C++180358681932054891219500
g++ (-O2)C++200381841376054881613960
clang++ (debug)C++150422401889054886819040
clang++ (-O2)C++200458241387054882014070
javac, javaJava1130653244896090665250090
hhvmPHP8992087746889920
rubyRuby114670870612114670
nodeJavascript1744041114417440
jsc-3Javascript6008083474460080
js24Javascript1927073555619270
goGo140304281145025162811590
scalaScala83420109392483420
python3Python 3121330641844121330
pypyPython 21472052208014720
luaLua9811086388098110
luajitLua2130051126821300
dartDart1192049778811920

Write down your opinion (or pastie if you found a bug on these source, or if you want to add more language implementation) on the comment section ^^)b

Note #1PHP 5.6.4, Rubinius 2.5.2, JRuby 9.0.0a1, Rhino 1.7, MCS 3.12 failed to end their execution within approx. 120s timeout

2015-02-10

If Programming Languages were Religions

This is old (2008) but still fun to re-read ^_^;;
Re-blogged from higherorderfun (Rodrigo Monteiro).
(Inspired by “If programming languages were cars“)
See other comparison about programming language and anything here.

C would be Judaism - it’s old and restrictive, but most of the world is familiar with its laws and respects them. The catch is, you can’t convert into it – you’re either into it from the start, or you will think that it’s insanity. Also, when things go wrong, many people are willing to blame the problems of the world on it.

Java would be Fundamentalist Christianity – it’s theoretically based on C, but it voids so many of the old laws that it doesn’t feel like the original at all. Instead, it adds its own set of rigid rules, which its followers believe to be far superior to the original. Not only are they certain that it’s the best language in the world, but they’re willing to burn those who disagree at the stake.

PHP would be Cafeteria Christianity – Fights with Java for the web market. It draws a few concepts from C and Java, but only those that it really likes. Maybe it’s not as coherent as other languages, but at least it leaves you with much more freedom and ostensibly keeps the core idea of the whole thing. Also, the whole concept of “goto hell” was abandoned.

C++ would be Islam - It takes C and not only keeps all its laws, but adds a very complex new set of laws on top of it. It’s so versatile that it can be used to be the foundation of anything, from great atrocities to beautiful works of art. Its followers are convinced that it is the ultimate universal language, and may be angered by those who disagree. Also, if you insult it or its founder, you’ll probably be threatened with death by more radical followers.

C# would be Mormonism - At first glance, it’s the same as Java, but at a closer look you realize that it’s controlled by a single corporation (which many Java followers believe to be evil), and that many theological concepts are quite different. You suspect that it’d probably be nice, if only all the followers of Java wouldn’t discriminate so much against you for following it.

Lisp would be Zen Buddhism – There is no syntax, there is no centralization of dogma, there are no deities to worship. The entire universe is there at your reach – if only you are enlightened enough to grasp it. Some say that it’s not a language at all; others say that it’s the only language that makes sense.

Haskell would be Taoism - It is so different from other languages that many people don’t understand how can anyone use it to produce anything useful. Its followers believe that it’s the true path to wisdom, but that wisdom is beyond the grasp of most mortals.

Erlang would be Hinduism – It’s another strange language that doesn’t look like it could be used for anything, but unlike most other modern languages, it’s built around the concept of multiple simultaneous deities.

Perl would be Voodoo – An incomprehensible series of arcane incantations that involve the blood of goats and permanently corrupt your soul. Often used when your boss requires you to do an urgent task at 21:00 on friday night.

Lua would be Wicca – A pantheistic language that can easily be adapted for different cultures and locations. Its code is very liberal, and allows for the use of techniques that might be described as magical by those used to more traditional languages. It has a strong connection to the moon.

Ruby would be Neo-Paganism – A mixture of different languages and ideas that was beaten together into something that might be identified as a language. Its adherents are growing fast, and although most people look at them suspiciously, they are mostly well-meaning people with no intention of harming anyone.

Python would be Humanism: It’s simple, unrestrictive, and all you need to follow it is common sense. Many of the followers claim to feel relieved from all the burden imposed by other languages, and that they have rediscovered the joy of programming. There are some who say that it is a form of pseudo-code.

COBOL would be Ancient Paganism – There was once a time when it ruled over a vast region and was important, but nowadays it’s almost dead, for the good of us all. Although many were scarred by the rituals demanded by its deities, there are some who insist on keeping it alive even today.

APL would be Scientology – There are many people who claim to follow it, but you’ve always suspected that it’s a huge and elaborate prank that got out of control.

LOLCODE would be Pastafarianism – An esoteric, Internet-born belief that nobody really takes seriously, despite all the efforts to develop and spread it.

Visual Basic would be Satanism - Except that you don’t REALLY need to sell your soul to be a Satanist…

Thanks to jfs and other people on #aegisub for the suggestions. Keep in mind, this list is a joke, and is not meant to offend anyone. Also, if you’re a ******, please don’t kill me.

-- and some of the comments (butt-hurt people and flames filtered)

Well if you want to add JavaScript to the list, how about we class it under Black Magic. Seeing how it is something designed to help us achieve good, with unintentional consequences beyond our comprehension, plus it can be used by evil doers to control, spy and mess with the innocent. I personally use as little as possible JavaScript, resorting more to server side code if possible. Or Alcoholism, the more you do it, the more it rots your brain as you realize that functions are objects, your prototypes are polluting namespaces, and you just can't seem to get any closure. Or Jedi Religion. Those who master it can do anything.

What about Prolog? Surely that'd be Atheism (yeah - I know, not technically a religion, but you know what I mean) a completely rationalistic take on the programming universe by following scientific deduction.

Smalltalk is the ancient Egyptian religion. The Initiated know it already had all the important concepts working long ago and most popular modern languages are incomplete subsets of it that obsess over artificial restrictions of their own creation while entirely missing the reason their code exists in the first place. And the heart of your code will be judged against the Feather of Truth before it can join the message passing afterlife. Smalltalk would be Freemasonry: lots of companies know it and use it but are afraid to say they do because it is a competitive advantage to them. Therefore it is a close, near-secret society of users. Moreover Smalltalk programs use reflection as means to improve themselves, which is one of the key principles in freemasonry. Last but not least they are viewed by several other religions as ancient outcasts, but they know better and are still quietly changing the world and influencing others.

Machine Language is Animism - the belief that ultimately everything is made out of bits and on some level can be thought of as an executable.

Assembly Language is Shamanism - the idea that we can use symbols to more easily communicate with the binary world. Also that we can change the visible world by journying into the hidden realm by the use of debuggers. Or Assembly is Atheism... followers believe that whatever you do, there is only the reality on the chip. You shouldn't need intermediary or 'fake' rules to deal with the reality right in front of you, but they can be useful for guidance so long as you don't believe them. They believe if you can handle it, you are enlightened, but understand a human need for simplicity. Try to argue with them though, and you'll get an earful.

Delphi is obviously Catholic. We enjoy lots of structure, and the VCL/RTL protects us from making most windows calls directly. It was founded (created) by somebody who is said to have super-human (very good technical) abilities. It grew to a point where it had a lot of power and followers. Many things have changed since Delphi was founded and, somehow, it has managed to evolve and grow (Delphi for .NET), however, in the process, it has lost the consistency that characterized its earlier flavors. Due to gross mistakes in its leadership (yeah, Borland), Delphi has lost ground to newer religions like C#, dynamic languages and, of course, the Web; but it still manages to survive and grow within its possibilities. -- Pascal/Delphi is Church of England. Once having quite an extensive and radical following, it has since mellowed out a lot. These days its followers have mostly given up on converting the world to their point of view. It's looked down at with some bemusement by some of the bigger languages that see themselves as more serious. Has trouble attracting young people. Pascal is Catholicism, it's old, was meant as a universal language, developed in a town that has climate similar to Rome, a language with no actual compilers--only interpreters, a language in which most anybody who does any programming had to learn, a language that no one practices, a language with simple but very strict rules making it a very litigious language such that if you don't follow all of the rules all of the time to the minutest detail, you will never experience the joy of getting your program to actually run, only frustration, confusion and guilt.

Fortran would be like the Amish faith - there's a relatively small number of programmers that use it, they don't try to proselytize others into using Fortran (perhaps knowing it's futile), and if you weren't born into it (that is, it wasn't the first or second major programming language you learned) there's about zero chance you'll ever understand it (and if you do learn a little about it later in life, you'll shake your head and wonder how anyone could adhere to it). And yet its adherents refuse to let it die. Also if you have programmed in Fortran for years and then discover another language you like better you'll probably never go back, so it's likely those in the "Fortran forever" camp will shun you from then on (at least they will never admit that your new preferred language could possibly be better!). But no one denies that you can run Fortran successfully on horse-and-buggy era computers (metaphorically speaking, of course!) and if, someday, something (like an EMP) destroys all the semiconductor-based computers, the Fortran guys will probably be able to run their language on the old vacuum-tube based Univac computers, and will therefore be far ahead of their peers who need the modern semiconductor-based technology to accomplish anything!

Objective-C would be Jews for Jesus. They want to keep the old ways, and extend them in a lovey dovey easy-to-use ways.

Groovy is Emergent Christianity: it comes from Java, but it's much hipper, its adherents look down on the Java followers they're still friends with, and they're a lot less concerned about putting things into such rigid categories. It's also low on ceremony and can easily modify itself as needed.

RPG would be Jehovah’s Witnesses. RPG programmers are of the elite 144,000 left in the world (because there are only 144,000 left in the world) and believe we are in the last days of the present world and lots of people make fun of them for their beliefs and rigid standards

Applescript is an analogy to Shinto: It pervades everyday life on Mac OS X, has few requirements or taboos, has been around practically forever (it started life as Hypercard), and is easy to get your mind around. It also has Steve Jobs as its Amaterasu. The only problem: As Shinto is confined solely to Japan, so Applescript is confined solely to Mac OS X and is found nowhere else.

Postscript is like one of those weird native south american religions where you have to get completely mashed on psychoactive herbs to program in it and then spend the next two days solid vomiting

Forth is like Kaballah, learning it requires lots of meditation on stuff like number theory and the calculus of infinitesimals, and any written stuff on it sounds to the uninitiated to be solid gibberish, but once you know it you see that it's just a systemization of minimalism-worship.

Clojure would be Unitarian Universalism. Although technically based on Java, it looks more like an eccentric version of Lisp. Somehow, the Renaissance and Enlightenment managed to produce, on a foundation of Java, a language that has the spare simplicity, lack of doctrine, and freedom of Lisp, that nevertheless, somehow, is able to coexist peacefully and productively with Java, while also incorporating modern ideals found in neither.

Ada is Anglicanism. Created by fiat as the official language of the government but nobody really pays it much attention anymore.

Brainf*ck, I think, would be Discordianism. Is it a programming language disguised as a joke, or is it a joke, disguised as a programming language..?

Check the next blogpost, if programming langauge were woman.