I've found some time to support JavaScript, which is so popular now. I chose V8 as the most developed implementation of JavaScript.
With the help of a tambourine and a liter of cola I successfully compiled it on Windows. Funny, I was ready to implement workaround to support reading from stdin in JavaScript, but d8
already supports it! Just use readline()
to read line from the input.
Here is an example of A+B:
var line = readline().split(' ')
print(parseInt(line[0]) + parseInt(line[1]))
Interesting fact, that if there is no line-break (\r\n) at the end of line, then readline()
returns undefined
. So it is one more reason for good rule: each line should end with eoln.
As a tiny research I've implemented HeapSort on C++, Java and JavaScript. I have an opinion that all dynamic typed languages are very slow. But...
I've implemented HeapSort on 107 elements from 0 to 9999999. I think it is good benchmark to show how fast can be your code if you write like in Pascal or pure C. The result have surprised me:
Language | Compiler | Running time, ms |
---|---|---|
C++ | MinGW 4.7.2 32-bit | 630 |
C++ | MS VS 2010 32-bit | 650 |
Java | Oracle Java 6 32-bit | 1060 |
Java | Oracle Java 7 32-bit | 1050 |
JavaScript | V8 3.23.0 32-bit | 1700 |
Pascal | Delphi 7 32-bit | 630 |
Pascal | FreePascal 2.6.2 32-bit | 730 |
Python 2 | Python 2.7.4 32-bit | 12500 |
Python 3 | Python 3.3.2 32-bit | 20000 |
Ruby | Ruby 1.9.3p0 (2011-10-30, i386-mingw32) 32-bit | 520000 |
Ruby | Ruby 2.0.0p353 (2013-11-22, i386-mingw32) 32-bit | 345000 |
Scala | Scala 2.10.3 (over Oracle Java 7 32-bit) | 1550 |
Go | Go 1.2 32-bit | 1780 |
D | DMD v2.064.2 32-bit | 800 |
C# | Mono 2.10.9 32-bit | 850 |
C# | MS CSC .Net 4.5.1 64-bit | 850 |
Perl | Perl v5.12.2 for MSWin32-x86-multi-thread | 195000 |
JavaScript shows very good performance! I understand that such kind of code is very good for optimization and jit-compilation, but I'm impressed. By the way, Java with its optimized JIT is not as good as it can be.
Actually, I posted the codes in github. You may implement the same algorithm on your favorite language. Here are links to current implementations:
You may post links to pastebin in comments or give submission id. Better to do a pull request.
If you are planning to write implementation, please write it neat and tidy. Write it as closer to the C++, Java and JavaScript as possible.
UPD 1. With the help of alexei-zayakin, Pascal has been added.
UPD 2. With the help of gchebanov Wizmann and juancate I've added Python 2, Python 3, Ruby, Scala, Go.
UPD 3. Here is V8 (Windows binaries).
UPD 4. I've updated some compilers and the benchmark results.
UPD 5. Added D. Thanks Gassa.
UPD 6. Added C#. Thanks gmogelashvili.