Ioke runs iterative fibonacci


Today Ioke actually runs both recursive and iterative fibonacci. That might not seem as much, but the work to get that has put in place much of the framework needed for the rest of the implementation.

It’s a nice milestone, since Ioke is now Turing complete (having both conditionals and iteration). Most of the neat features I’m planning aren’t actually implemented yet, though.

In the time honored tradition of language performance measuring, I decided to compare iterative fibonacci performance to Ruby.

Keep in mind that I haven’t done any optimizations whatsoever, and I do loads of really expensive stuff all over Ioke. Specifically, there is no such thing as locals – what looks like locals here are actually regular attributes of a Context object. All lookup of names are using hash tables at the moment. It’s also fully interpreted code. Nothing is being compiled at this point. I’m running all the examples on SoyLatte (Java 1.6) on a MBP. I used the JVM -server flag when running Ioke and JRuby.

The Ruby code looks like this:

require 'benchmark'

def fib_iter_ruby(n)
   i = 0
   j = 1
   cur = 1
   while cur <= n
     k = i
     i = j
     j = k + j
     cur = cur + 1
   end
   i
end

puts Benchmark.measure { fib_iter_ruby(300000) }
puts Benchmark.measure { fib_iter_ruby(300000) }

And the Ioke code looks like this. I don’t have any benchmarking libraries yet, so I measured it using time:

fib = method(n,
  i = 0
  j = 1
  cur = 1
  while(cur <= n,
    k = i
    i = j
    j = k + j
    cur++)
  i)

System ifMain(fib(300000))

And what are the results? Not surprisingly, JRuby does well on this benchmark, and would probably do even better if I ran more iterations. The JRuby (this is current trunk, btw) time for calculating fib(300000) was 7.5s. MRI (ruby 1.8.6 (2008-03-03 patchlevel 114) [i686-darwin8.10.1]) ended up at exactly 14s. So where is Ioke in all this? I’m happy to say Ioke ended up taking 9.2s. I was really pleasantly surprised by that. But I have a feeling that recursive fib might not end up with those proportions. But the indication is that I haven’t done anything amazingly expensive yet, at least. That’s a good sign, although I have no problem sacrificing performance for expressability.


5 Comments, Comment or Ping

  1. Congrats, Ola! Ioke is looking really nice — looking forward to playing with it :)

    October 14th, 2008

  2. Wow interesting this ist the first “micro benchmark” which is slower in ruby1.9 than in 1.8 on my mbp. All other benchmarks i ran so far (non were really serious) were 4-10 times faster in 1.9

    Hrm

    October 14th, 2008

  3. Jean-Baptiste Potonnier

    Hello Ola
    I’m following your work silently, because I love Io language.
    And I had the same idea to create an Io-like language for the JVM. But I’am not brave enough to do it.

    Congratulation, it is nice to see something concrete :)
    I will continue to follow your work with enthousiasm

    JB

    October 15th, 2008

  4. Patrick

    As a JVM developer, I’m glad to see your Ruby version calls the benchmark twice. I presume you reported the time taken for the second call?

    Did you call the Ioke version twice too?

    November 11th, 2008

  5. Hmm. Speed is always welcome :)
    At the same time this is my first introduction to loke and…the syntax of that snippet looks far less clean than ruby to my untrained eye. Just giving some feedback. It has potential, just looks like a long list of parameters to a function.
    Cheers!
    -=R

    December 8th, 2008

Reply to “Ioke runs iterative fibonacci”