Tuesday, 30 October 2012

Want to do maths? You are 120x better off with Scala than Perl

To be honest, I did expect some difference in performance between statically typed Scala (JVM-based language) and dynamic Perl... but maybe not that big. Anyway, check it out.

Here is a very simple way to compute prime numbers:

==== PrimeNumbers.scala
object PrimeNumbers {
   def isPrime(n: Int): Boolean = (2 until n) forall (d => n % d != 0)
   def main(args: Array[String]): Unit = {
    (8999999 until 8999999+200).map(x => if (isPrime(x)) print(x+" ") )

==== prime_numbers.pl
sub isPrime {
    my $n = shift;
    grep( $n % $_ == 0, (2..($n-1))) ? 0 : 1

for(8999999..(8999999+200)) {
    isPrime($_) && print "$_\n"

time scala PrimeNumbers
9000011 9000041 9000049 9000059 9000067 9000119 9000127 9000143 9000163 9000193
real    0m3.187s

time perl prime_numbers.pl
real    6m23.221s

Really? This huge JVM-bloated Scala is about 120x faster in such things than Perl... can't belive!

(Perl v5.14.2, Scala 2.9.1)

Friday, 4 May 2012

Missed your Germanwings flight departure from London Heathrow or Stansted?

Do you trust your airline when checking your flight departure? If they have no idea of "local time" and concept of time zones, be careful or you can miss your flight! I just wonder how many passengers of Germanwings airline flying from UK are going to find that their flight has just gone... according to schedule.... errrr... what schedule? They publish departures times in "their" time zone, not the local one. It is weird, but... well... it is Germanwings. You've been warned.

 Germanwings airline website:
London Heathrow airport website:

Ps - I spent some creative time working with time zones code. It is definitely not an easy thing even if it seems to be quite obvious.
Ps 2 - Germanwings has no email, only premium phone numbers. No way to report them a bug, sorry Germanwings passengers.
Ps 3 - It is not like intermittent - after 2 weeks, they are still proud to have this silly bug.
Ps 4 - It looks like Germanwings... well... I hope they are never going to fly from New York or Dubai.