Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

High-performance Ruby: faster Symbol.to_s

Here's something that I found useful for shaving a few microseconds off. The performance gain ranges between 10% and 35%! YMMV.

Note: updated with suggestion by trans.

   1  
   2  class Symbol
   3    def to_s
   4      @str_rep || (@str_rep = id2name.freeze)
   5    end
   6  end

Get mobile cpu speed

   1  
   2  import miso
   3  print miso.get_hal_attr(11)  # 104000 for my 6600

Use timeit module

   1  
   2  >>> from timeit import Timer
   3  >>> t = Timer('md5.new("md5 is not safe").digest()', 'import md5')
   4  >>> t.timeit()
   5  2.6892227922821803

Quite useful to compare speed of codes.
Read more here
http://diveintopython.org/performance_tuning/timeit.html
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS