Skip to content

Instantly share code, notes, and snippets.

@sferik
Forked from carllerche/gist:177377
Created January 5, 2010 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferik/269793 to your computer and use it in GitHub Desktop.
Save sferik/269793 to your computer and use it in GitHub Desktop.
Thread.new is slow
require "rubygems"
require "rbench"
def noop
end
RBench.run(100_000) do
column :one, :title => "Unthreaded"
column :two, :title => "Threaded"
report "Thread.new is slow" do
one{noop}
two{Thread.new{noop}}
end
end
__END__
# Ruby 1.8.7-p302
Unthreaded | Threaded |
--------------------------------------------------
Thread.new is slow 0.022 | 8.644 |
# Ruby 1.9.2
Unthreaded | Threaded |
--------------------------------------------------
Thread.new is slow 0.013 | 13.448 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment