public
Created

  • Download Gist
gistfile2.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
ruby 1.8.7 (2009-09-11 patchlevel 202) [x86_64-linux]
 
Rehearsal -----------------------------------------------------------------
large hash empty 0.700000 0.000000 0.700000 ( 0.708355)
large hash ek empty 0.170000 0.000000 0.170000 ( 0.168563)
large set empty 1.090000 0.000000 1.090000 ( 1.099709)
large myset empty 0.170000 0.000000 0.170000 ( 0.172110)
large hash work 1.190000 0.000000 1.190000 ( 1.193358)
large hash ek work 0.630000 0.000000 0.630000 ( 0.631994)
large set work 1.610000 0.000000 1.610000 ( 1.610816)
large myset work 0.620000 0.000000 0.620000 ( 0.616951)
small hash empty 0.800000 0.000000 0.800000 ( 0.807009)
small hash ek empty 0.240000 0.000000 0.240000 ( 0.234455)
small set empty 1.260000 0.000000 1.260000 ( 1.258397)
small myset empty 0.560000 0.000000 0.560000 ( 0.563852)
small hash work 1.290000 0.000000 1.290000 ( 1.286641)
small hash ek work 0.710000 0.000000 0.710000 ( 0.709628)
small set work 1.780000 0.000000 1.780000 ( 1.780012)
small myset work 1.020000 0.000000 1.020000 ( 1.027609)
------------------------------------------------------- total: 13.840000sec
 
user system total real
large hash empty 0.740000 0.000000 0.740000 ( 0.746104)
large hash ek empty 0.160000 0.000000 0.160000 ( 0.169235)
large set empty 1.100000 0.000000 1.100000 ( 1.097890)
large myset empty 0.160000 0.000000 0.160000 ( 0.168091)
large hash work 1.230000 0.000000 1.230000 ( 1.223093)
large hash ek work 0.650000 0.000000 0.650000 ( 0.643507)
large set work 1.620000 0.000000 1.620000 ( 1.620876)
large myset work 0.630000 0.000000 0.630000 ( 0.620672)
small hash empty 0.810000 0.000000 0.810000 ( 0.812050)
small hash ek empty 0.220000 0.000000 0.220000 ( 0.223639)
small set empty 1.270000 0.000000 1.270000 ( 1.268244)
small myset empty 0.560000 0.000000 0.560000 ( 0.552596)
small hash work 1.280000 0.000000 1.280000 ( 1.282446)
small hash ek work 0.710000 0.000000 0.710000 ( 0.714125)
small set work 1.790000 0.000000 1.790000 ( 1.794222)
small myset work 1.010000 0.000000 1.010000 ( 1.012198)
gistfile3.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
ruby 1.9.1p243 (2009-07-16) [x86_64-linux]
 
Rehearsal -----------------------------------------------------------------
large hash empty 1.240000 0.000000 1.240000 ( 1.243310)
large hash ek empty 0.160000 0.000000 0.160000 ( 0.163349)
large set empty 0.220000 0.000000 0.220000 ( 0.225271)
large myset empty 0.160000 0.000000 0.160000 ( 0.162076)
large hash work 1.380000 0.020000 1.400000 ( 1.394115)
large hash ek work 0.320000 0.000000 0.320000 ( 0.326132)
large set work 0.400000 0.000000 0.400000 ( 0.391870)
large myset work 0.330000 0.000000 0.330000 ( 0.332589)
small hash empty 1.240000 0.000000 1.240000 ( 1.238724)
small hash ek empty 0.180000 0.000000 0.180000 ( 0.178892)
small set empty 0.270000 0.010000 0.280000 ( 0.277523)
small myset empty 0.320000 0.010000 0.330000 ( 0.322598)
small hash work 0.680000 0.000000 0.680000 ( 0.694154)
small hash ek work 0.350000 0.000000 0.350000 ( 0.349957)
small set work 0.430000 0.000000 0.430000 ( 0.431274)
small myset work 0.490000 0.000000 0.490000 ( 0.493518)
-------------------------------------------------------- total: 8.210000sec
 
user system total real
large hash empty 0.510000 0.000000 0.510000 ( 0.507302)
large hash ek empty 0.160000 0.000000 0.160000 ( 0.161416)
large set empty 0.230000 0.000000 0.230000 ( 0.223124)
large myset empty 0.160000 0.000000 0.160000 ( 0.160507)
large hash work 0.830000 0.000000 0.830000 ( 0.828240)
large hash ek work 0.320000 0.000000 0.320000 ( 0.323904)
large set work 0.390000 0.000000 0.390000 ( 0.392084)
large myset work 0.330000 0.000000 0.330000 ( 0.334701)
small hash empty 0.660000 0.000000 0.660000 ( 0.664095)
small hash ek empty 0.180000 0.000000 0.180000 ( 0.176685)
small set empty 0.260000 0.000000 0.260000 ( 0.267225)
small myset empty 0.300000 0.000000 0.300000 ( 0.302558)
small hash work 0.700000 0.000000 0.700000 ( 0.694463)
small hash ek work 0.340000 0.000000 0.340000 ( 0.348215)
small set work 0.430000 0.000000 0.430000 ( 0.428701)
small myset work 0.490000 0.000000 0.490000 ( 0.487979)
gistfile4.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
ruby 1.8.7 (2009-09-11 patchlevel 202) [x86_64-linux] with SMALL = 100
 
Rehearsal -----------------------------------------------------------------
large hash empty 7.120000 0.000000 7.120000 ( 7.140655)
large hash ek empty 1.690000 0.000000 1.690000 ( 1.683248)
large set empty 10.800000 0.010000 10.810000 ( 10.842401)
large myset empty 1.670000 0.000000 1.670000 ( 1.672896)
large hash work 12.040000 0.000000 12.040000 ( 12.041704)
large hash ek work 6.380000 0.000000 6.380000 ( 6.382304)
large set work 16.070000 0.000000 16.070000 ( 16.066048)
large myset work 6.360000 0.000000 6.360000 ( 6.463861)
small hash empty 7.570000 0.000000 7.570000 ( 7.582119)
small hash ek empty 1.790000 0.000000 1.790000 ( 1.783863)
small set empty 11.020000 0.000000 11.020000 ( 11.025360)
small myset empty 2.110000 0.010000 2.120000 ( 2.119414)
small hash work 12.310000 0.000000 12.310000 ( 12.310792)
small hash ek work 6.510000 0.000000 6.510000 ( 6.513175)
small set work 16.250000 0.000000 16.250000 ( 16.258754)
small myset work 6.760000 0.000000 6.760000 ( 6.768757)
------------------------------------------------------ total: 126.470000sec
 
user system total real
large hash empty 7.510000 0.000000 7.510000 ( 7.510285)
large hash ek empty 1.680000 0.000000 1.680000 ( 1.689755)
large set empty 10.890000 0.000000 10.890000 ( 10.890979)
large myset empty 1.690000 0.000000 1.690000 ( 1.684118)
large hash work 12.330000 0.000000 12.330000 ( 12.331743)
large hash ek work 6.470000 0.000000 6.470000 ( 6.462357)
large set work 16.290000 0.000000 16.290000 ( 16.291570)
large myset work 6.420000 0.000000 6.420000 ( 6.414107)
small hash empty 7.570000 0.000000 7.570000 ( 7.576899)
small hash ek empty 1.790000 0.000000 1.790000 ( 1.785385)
small set empty 11.110000 0.000000 11.110000 ( 11.111415)
small myset empty 2.110000 0.000000 2.110000 ( 2.116767)
small hash work 12.360000 0.000000 12.360000 ( 12.369393)
small hash ek work 6.570000 0.000000 6.570000 ( 6.567924)
small set work 16.360000 0.000000 16.360000 ( 16.366101)
small myset work 6.770000 0.000000 6.770000 ( 6.767472)
gistfile5.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
ruby 1.9.1p243 (2009-07-16) [x86_64-linux] with SMALL = 100
 
Rehearsal -----------------------------------------------------------------
large hash empty 12.280000 0.000000 12.280000 ( 12.307787)
large hash ek empty 1.590000 0.010000 1.600000 ( 1.599274)
large set empty 2.160000 0.000000 2.160000 ( 2.169838)
large myset empty 1.600000 0.000000 1.600000 ( 1.599373)
large hash work 13.860000 0.010000 13.870000 ( 13.861249)
large hash ek work 3.230000 0.000000 3.230000 ( 3.237656)
large set work 3.850000 0.000000 3.850000 ( 3.847627)
large myset work 3.250000 0.000000 3.250000 ( 3.249806)
small hash empty 12.200000 0.000000 12.200000 ( 12.215606)
small hash ek empty 1.620000 0.010000 1.630000 ( 1.627360)
small set empty 2.160000 0.000000 2.160000 ( 2.159315)
small myset empty 1.730000 0.010000 1.740000 ( 1.731791)
small hash work 7.890000 0.010000 7.900000 ( 7.909811)
small hash ek work 3.250000 0.000000 3.250000 ( 3.255006)
small set work 3.820000 0.000000 3.820000 ( 3.814084)
small myset work 3.360000 0.000000 3.360000 ( 3.371485)
------------------------------------------------------- total: 77.900000sec
 
user system total real
large hash empty 6.210000 0.000000 6.210000 ( 6.204165)
large hash ek empty 1.600000 0.000000 1.600000 ( 1.597472)
large set empty 2.160000 0.000000 2.160000 ( 2.159800)
large myset empty 1.600000 0.000000 1.600000 ( 1.607146)
large hash work 8.060000 0.010000 8.070000 ( 8.062599)
large hash ek work 3.230000 0.000000 3.230000 ( 3.243833)
large set work 3.850000 0.000000 3.850000 ( 3.853430)
large myset work 3.240000 0.000000 3.240000 ( 3.237876)
small hash empty 6.320000 0.000000 6.320000 ( 6.308652)
small hash ek empty 1.620000 0.010000 1.630000 ( 1.625322)
small set empty 2.150000 0.000000 2.150000 ( 2.153468)
small myset empty 1.710000 0.000000 1.710000 ( 1.709837)
small hash work 7.720000 0.010000 7.730000 ( 7.799120)
small hash ek work 3.250000 0.010000 3.260000 ( 3.249664)
small set work 3.810000 0.000000 3.810000 ( 3.811161)
small myset work 3.370000 0.000000 3.370000 ( 3.371556)
sb.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
require 'set'
require 'benchmark'
 
class MySet
include Enumerable
 
def initialize(enum)
@h = {}
enum.each {|x,| @h[x] = true}
end
 
def each(&b)
@h.each_key(&b)
self
end
end
 
SMALL = 10
LARGE = 100_000
 
def work(x)
x << 10
end
 
sms = (1..SMALL).to_set.freeze
smmy = MySet.new(sms).freeze
smh = {}
sms.each {|k| smh[k] = true}
smh.freeze
 
ls = (1..LARGE).to_set.freeze
lmy = MySet.new(ls).freeze
lh = {}
ls.each {|k| lh[k] = true}
lh.freeze
 
Benchmark.bmbm 30 do |b|
 
b.report "large hash empty" do
SMALL.times do
lh.each {|k,e| }
end
end
 
b.report "large hash ek empty" do
SMALL.times do
lh.each_key {|k| }
end
end
 
b.report "large set empty" do
SMALL.times do
ls.each {|e| }
end
end
 
b.report "large myset empty" do
SMALL.times do
lmy.each {|e| }
end
end
 
b.report "large hash work" do
SMALL.times do
lh.each {|k,e| work k}
end
end
 
b.report "large hash ek work" do
SMALL.times do
lh.each_key {|k| work k}
end
end
 
b.report "large set work" do
SMALL.times do
ls.each {|e| work e}
end
end
 
b.report "large myset work" do
SMALL.times do
lmy.each {|e| work e}
end
end
 
# -----------------
 
b.report "small hash empty" do
LARGE.times do
smh.each {|k,e| }
end
end
 
b.report "small hash ek empty" do
LARGE.times do
smh.each_key {|k| }
end
end
 
b.report "small set empty" do
LARGE.times do
sms.each {|e| }
end
end
 
b.report "small myset empty" do
LARGE.times do
smmy.each {|e| }
end
end
 
b.report "small hash work" do
LARGE.times do
smh.each {|k,e| work k}
end
end
 
b.report "small hash ek work" do
LARGE.times do
smh.each_key {|k| work k}
end
end
 
b.report "small set work" do
LARGE.times do
sms.each {|e| work e}
end
end
 
b.report "small myset work" do
LARGE.times do
smmy.each {|e| work e}
end
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.