Skip to content

Instantly share code, notes, and snippets.

@sdsykes
Created February 21, 2010 20:21
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 sdsykes/310510 to your computer and use it in GitHub Desktop.
Save sdsykes/310510 to your computer and use it in GitHub Desktop.
466c466
< if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
---
> if (RHASH(hash)->tbl->num_entries == 0 || !st_lookup(RHASH(hash)->tbl, key, &val)) {
require 'benchmark'
test = lambda do |n|
lambda do
h = {}
h2 = {"a"=>"b"}
10_000.times do |y|
str = "a" * n
sym = str.intern
100.times do
h[str]
h[sym]
h2[str]
h2[sym]
end
end
end
end
Benchmark.bm do |b|
7.times do |n|
b.report("#{1<<n}x", &test.call(1<<n))
end
end
user system total real
1x 1.750000 0.010000 1.760000 ( 1.759984)
2x 1.830000 0.000000 1.830000 ( 1.828848)
4x 1.840000 0.000000 1.840000 ( 1.847043)
8x 1.840000 0.010000 1.850000 ( 1.843167)
16x 1.840000 0.000000 1.840000 ( 1.848768)
32x 1.850000 0.000000 1.850000 ( 1.849023)
64x 1.850000 0.010000 1.860000 ( 1.857963)
user system total real
1x 1.680000 0.000000 1.680000 ( 1.688379)
2x 1.780000 0.010000 1.790000 ( 1.777302)
4x 1.780000 0.000000 1.780000 ( 1.783551)
8x 1.770000 0.000000 1.770000 ( 1.780911)
16x 1.790000 0.010000 1.800000 ( 1.786330)
32x 1.780000 0.000000 1.780000 ( 1.790252)
64x 1.800000 0.000000 1.800000 ( 1.800255)
user system total real
1x 1.630000 0.000000 1.630000 ( 1.636553)
2x 1.740000 0.000000 1.740000 ( 1.735722)
4x 1.740000 0.010000 1.750000 ( 1.740702)
8x 1.750000 0.000000 1.750000 ( 1.760334)
16x 1.770000 0.000000 1.770000 ( 1.775435)
32x 1.840000 0.010000 1.850000 ( 1.835240)
64x 1.920000 0.000000 1.920000 ( 1.933402)
user system total real
1x 1.690000 0.000000 1.690000 ( 1.690578)
2x 1.770000 0.010000 1.780000 ( 1.780384)
4x 1.800000 0.000000 1.800000 ( 1.796044)
8x 1.830000 0.000000 1.830000 ( 1.835327)
16x 1.860000 0.010000 1.870000 ( 1.866744)
32x 1.950000 0.000000 1.950000 ( 1.951703)
64x 2.110000 0.000000 2.110000 ( 2.117919)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment