The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Best of both worlds

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ryan Davis

Posts: 651
Nickname: zenspider
Registered: Oct, 2004

Ryan Davis is a ruby nerd.
Best of both worlds Posted: Mar 7, 2006 4:17 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Ryan Davis.
Original Post: Best of both worlds
Feed Title: Polishing Ruby
Feed URL: http://blog.zenspider.com/index.rdf
Feed Description: Musings on Ruby and the Ruby Community...
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Ryan Davis
Latest Posts From Polishing Ruby

Advertisement

Here is my very simple rule for optimizing:

Never ever code for speed until you need to code for speed!

Consider it an addendum to Knuth's "root of all evil" law. There are two corollaries to this law:

Always measure.

and

Only rewrite the slow part in C, not the whole damn thing.

Some of this came up recently because of a dialog last week on ruby-talk between Sascha Ebach and JEG2 about making FasterCSV even faster. James wants to keep the module as pure ruby (totally laudable goal) but Sascha thought it'd be neat to take advantage of RubyInline if it were available. I'm all for keeping it pure ruby, but I wanted to see how you'd do the dual implementation version in a way that still read clean. Here is my first scratch at it:

begin; require 'inline'; rescue LoadError; end

class MaybeFast
  def blah
    puts "slow version"
  end unless respond_to? :inline

  inline do |builder|
    builder.c 'void blah() { puts("fast version"); }'
  end if respond_to? :inline
end

MaybeFast.new.blah

Read: Best of both worlds

Topic: "Kestrel" is taken...and how! Previous Topic   Next Topic Topic: Implementación de Python para los teléfonos Nokia basados en S60 para Symbian

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use