gonium.net » profiling http://gonium.net/md so much time, so little to do. Sat, 11 Sep 2010 16:42:09 +0000 en hourly 1 http://wordpress.org/?v=3.0.1 Ruby 1.9 Performance http://gonium.net/md/2009/04/17/ruby-19-performance/ http://gonium.net/md/2009/04/17/ruby-19-performance/#comments Fri, 17 Apr 2009 09:51:15 +0000 md http://gonium.net/md/?p=146 I’m currently using Ruby to optimize schedules based on a simulated annealing approach. For my current intermediate version I rely on marshalling internal datastructures really frequently. Out of curiosity I compared the runtimes of Ruby 1.8 and 1.9:

  • Ruby 1.8.6: 21 minutes, 55 seconds
  • Ruby 1.9.0: 22 minutes, 13 seconds

I certainly did not expect any wonders, but in theis case, the runtimes are about the same. So I’m investigating further, using the ruby 1.8 profiler on a smaller test problem:


% cumulative self self total
time seconds seconds calls ms/call ms/call name
33.20 32.96 32.96 661 49.86 77.25 Marshal.load
17.80 50.63 17.67 6365 2.78 14.96 Array#each
17.52 68.03 17.40 601659 0.03 0.03 IO#getc
9.19 77.15 9.12 660 13.82 13.82 Marshal.dump
6.01 83.12 5.97 187158 0.03 0.03 Float#+

My code spends 42.39 percent of its runtime doing marshalling operations. For Ruby 1.9, the code spends 48.98 percent of its runtime doing marshalling. This is somewhat disappointing. In a second round I changed my code to not relying on marshalling – basically, I am using clone on essential internal datastructures. All other information can be reconstructed afterwards. This means that I need to recompute certain values, but evidently this is a much faster approach:

  • Ruby 1.8.6: 1 minute, 34 seconds
  • Ruby 1.9.0: 1 minute, 17 seconds

Note to self: always use a profiler before refactoring code for performance reasons.

]]>
http://gonium.net/md/2009/04/17/ruby-19-performance/feed/ 0