2008-09
Hitimes are upon us (2008-09-14)
Saturday afternoon at the Lone Star Ruby Conf I was discussing something, I forget exactly what, with Bruce and he mentioned that he was looking for a really fast way to measure elapsed time of a piece of code.
The naive approach would be call Time.now before and after the call, or maybe
use the
Time.elapse method
from Facets. Both of those approaches are
perfectly acceptable, and return results down to the µsecond. Can we do
better? Yes.
We have a goal of being faster than 2 successive Time.now calls. Each
operating system has a different way accessing a high-resolution timer.
- Unixes – the POSIX calls to
clock_gettime() - OS X –
UpTime() - Windows –
QueryPerformanceCounter()
Unify the C level interface to all of those, wrap it up in a Ruby extension and the result is the just-released Hitimes, a high-resolution timer library in Ruby for when you want to do measuring at the nanosecond level.
gem install hitimes
Interval
class. This does one really simple thing. It measures an interval of time.
You can measure code in a block:
require 'hitimes' require 'open-uri' duration = Hitimes::Interval.measure do bruce = open("http://www.codefluency.com/").read end puts duration # => 0.261841618
interval = Hitimes::Interval.new # do something interval.start # some code to measure duration = interval.stop
Interval, and a
Timer
class for measuring series of intervals and reporting statistics.
Post Lone Star Talk Thoughts (2008-09-08)

Fernand and I presented a talk at Lone Star Ruby Conf last Friday entitled Building and Managing a Ruby Infrastructure. It appears we hit upon a subject that people are starting encounter. Over the next couple of weeks I’ll post a few more articles explaining in more detail a few of the key concepts. For now, a few links to things that we mentioned in the talk.
- Bones—A great project templating tool, extendible to use your own proect templates.
- Rational Versioning Policy—in
which
~>a.k.a “Twiddle Wakka” is explained. - Stickler—organize and maintain an internal gem distribution server. Still in planning stages.
- take a look at the
gem indexandgem servercommands