Created
June 10, 2013 12:07
-
-
Save headius/5748268 to your computer and use it in GitHub Desktop.
Benchmarking kind_of?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
class A; end | |
class B < A; end | |
class C < B; end | |
class D < C; end | |
class E < D; end | |
class MyString < String; end | |
e = E.new | |
m = MyString.new | |
puts "10m kind_of? on a five-class hierarchy" | |
10.times { | |
puts Benchmark.measure { | |
i = 0 | |
while i < 10000000 | |
e.kind_of? A | |
i += 1 | |
end | |
} | |
} | |
puts "10m kind_of on a subclass of String" | |
10.times { | |
puts Benchmark.measure { | |
i = 0 | |
while i < 10000000 | |
m.kind_of? String | |
i += 1 | |
end | |
} | |
} | |
puts "10m * 10 failed kind_of against Fixnum" | |
10.times { | |
puts Benchmark.measure { | |
i = 0 | |
while i < 10000000 | |
i.kind_of? String | |
i.kind_of? Array | |
i.kind_of? Time | |
i.kind_of? Hash | |
i.kind_of? Class | |
i.kind_of? Module | |
i.kind_of? Bignum | |
i.kind_of? Float | |
i.kind_of? Binding | |
i.kind_of? NilClass | |
i += 1 | |
end | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEFORE, Java 6 | |
10m kind_of? on a five-class hierarchy | |
0.540000 0.020000 0.560000 ( 0.409000) | |
0.350000 0.020000 0.370000 ( 0.313000) | |
0.330000 0.020000 0.350000 ( 0.326000) | |
0.330000 0.020000 0.350000 ( 0.326000) | |
0.330000 0.010000 0.340000 ( 0.322000) | |
0.330000 0.020000 0.350000 ( 0.325000) | |
0.320000 0.010000 0.330000 ( 0.324000) | |
0.330000 0.020000 0.350000 ( 0.329000) | |
0.330000 0.020000 0.350000 ( 0.328000) | |
0.330000 0.020000 0.350000 ( 0.325000) | |
10m kind_of on a subclass of String | |
0.460000 0.010000 0.470000 ( 0.410000) | |
0.380000 0.020000 0.400000 ( 0.360000) | |
0.300000 0.020000 0.320000 ( 0.303000) | |
0.300000 0.010000 0.310000 ( 0.297000) | |
0.300000 0.020000 0.320000 ( 0.298000) | |
0.310000 0.020000 0.330000 ( 0.299000) | |
0.300000 0.010000 0.310000 ( 0.296000) | |
0.300000 0.020000 0.320000 ( 0.296000) | |
0.300000 0.020000 0.320000 ( 0.294000) | |
0.310000 0.010000 0.320000 ( 0.297000) | |
10m * 10 failed kind_of against Fixnum | |
3.120000 0.030000 3.150000 ( 2.920000) | |
2.960000 0.020000 2.980000 ( 2.865000) | |
2.310000 0.020000 2.330000 ( 2.279000) | |
2.300000 0.010000 2.310000 ( 2.293000) | |
2.310000 0.020000 2.330000 ( 2.305000) | |
2.410000 0.030000 2.440000 ( 2.407000) | |
2.260000 0.020000 2.280000 ( 2.265000) | |
2.210000 0.020000 2.230000 ( 2.215000) | |
2.210000 0.010000 2.220000 ( 2.213000) | |
2.230000 0.020000 2.250000 ( 2.222000) | |
AFTER, Java 6 | |
10m kind_of? on a five-class hierarchy | |
0.600000 0.030000 0.630000 ( 0.435000) | |
0.370000 0.010000 0.380000 ( 0.338000) | |
0.360000 0.020000 0.380000 ( 0.346000) | |
0.350000 0.020000 0.370000 ( 0.348000) | |
0.350000 0.010000 0.360000 ( 0.344000) | |
0.360000 0.020000 0.380000 ( 0.351000) | |
0.350000 0.020000 0.370000 ( 0.345000) | |
0.350000 0.010000 0.360000 ( 0.347000) | |
0.350000 0.020000 0.370000 ( 0.345000) | |
0.360000 0.020000 0.380000 ( 0.352000) | |
10m kind_of on a subclass of String | |
0.460000 0.020000 0.480000 ( 0.400000) | |
0.370000 0.010000 0.380000 ( 0.346000) | |
0.340000 0.020000 0.360000 ( 0.330000) | |
0.320000 0.010000 0.330000 ( 0.321000) | |
0.330000 0.020000 0.350000 ( 0.318000) | |
0.320000 0.020000 0.340000 ( 0.319000) | |
0.330000 0.010000 0.340000 ( 0.322000) | |
0.320000 0.020000 0.340000 ( 0.320000) | |
0.330000 0.020000 0.350000 ( 0.327000) | |
0.330000 0.010000 0.340000 ( 0.327000) | |
10m * 10 failed kind_of against Fixnum | |
2.280000 0.020000 2.300000 ( 2.112000) | |
2.040000 0.020000 2.060000 ( 1.991000) | |
2.010000 0.020000 2.030000 ( 1.980000) | |
1.970000 0.020000 1.990000 ( 1.968000) | |
1.980000 0.020000 2.000000 ( 1.974000) | |
2.000000 0.010000 2.010000 ( 1.991000) | |
1.980000 0.020000 2.000000 ( 1.971000) | |
1.960000 0.020000 1.980000 ( 1.964000) | |
1.960000 0.020000 1.980000 ( 1.951000) | |
1.960000 0.010000 1.970000 ( 1.960000) | |
BEFORE, Java 7u40 (+indy) | |
10m kind_of? on a five-class hierarchy | |
0.890000 0.050000 0.940000 ( 0.468000) | |
0.330000 0.020000 0.350000 ( 0.208000) | |
0.190000 0.000000 0.190000 ( 0.184000) | |
0.190000 0.000000 0.190000 ( 0.182000) | |
0.190000 0.000000 0.190000 ( 0.184000) | |
0.190000 0.000000 0.190000 ( 0.182000) | |
0.180000 0.010000 0.190000 ( 0.182000) | |
0.190000 0.000000 0.190000 ( 0.184000) | |
0.190000 0.000000 0.190000 ( 0.186000) | |
0.190000 0.000000 0.190000 ( 0.189000) | |
10m kind_of on a subclass of String | |
0.290000 0.000000 0.290000 ( 0.237000) | |
0.160000 0.000000 0.160000 ( 0.146000) | |
0.150000 0.000000 0.150000 ( 0.146000) | |
0.140000 0.010000 0.150000 ( 0.145000) | |
0.150000 0.000000 0.150000 ( 0.149000) | |
0.150000 0.000000 0.150000 ( 0.147000) | |
0.150000 0.000000 0.150000 ( 0.143000) | |
0.140000 0.000000 0.140000 ( 0.142000) | |
0.150000 0.000000 0.150000 ( 0.143000) | |
0.150000 0.000000 0.150000 ( 0.143000) | |
10m * 10 failed kind_of against Fixnum | |
1.630000 0.010000 1.640000 ( 1.389000) | |
1.190000 0.000000 1.190000 ( 1.101000) | |
1.060000 0.000000 1.060000 ( 1.031000) | |
1.030000 0.010000 1.040000 ( 1.021000) | |
1.030000 0.000000 1.030000 ( 1.025000) | |
1.030000 0.000000 1.030000 ( 1.022000) | |
1.020000 0.000000 1.020000 ( 1.020000) | |
1.030000 0.000000 1.030000 ( 1.029000) | |
1.050000 0.010000 1.060000 ( 1.033000) | |
1.050000 0.000000 1.050000 ( 1.025000) | |
AFTER, Java 7u40 (+indy) | |
10m kind_of? on a five-class hierarchy | |
0.920000 0.060000 0.980000 ( 0.476000) | |
0.320000 0.010000 0.330000 ( 0.209000) | |
0.180000 0.010000 0.190000 ( 0.182000) | |
0.190000 0.000000 0.190000 ( 0.185000) | |
0.190000 0.000000 0.190000 ( 0.185000) | |
0.190000 0.000000 0.190000 ( 0.182000) | |
0.190000 0.000000 0.190000 ( 0.184000) | |
0.180000 0.000000 0.180000 ( 0.181000) | |
0.190000 0.010000 0.200000 ( 0.183000) | |
0.180000 0.000000 0.180000 ( 0.183000) | |
10m kind_of on a subclass of String | |
0.310000 0.000000 0.310000 ( 0.239000) | |
0.160000 0.000000 0.160000 ( 0.136000) | |
0.130000 0.000000 0.130000 ( 0.126000) | |
0.130000 0.000000 0.130000 ( 0.127000) | |
0.130000 0.000000 0.130000 ( 0.125000) | |
0.130000 0.010000 0.140000 ( 0.129000) | |
0.140000 0.000000 0.140000 ( 0.129000) | |
0.130000 0.000000 0.130000 ( 0.125000) | |
0.130000 0.000000 0.130000 ( 0.128000) | |
0.130000 0.000000 0.130000 ( 0.126000) | |
10m * 10 failed kind_of against Fixnum | |
1.540000 0.010000 1.550000 ( 1.217000) | |
1.120000 0.010000 1.130000 ( 0.953000) | |
0.800000 0.000000 0.800000 ( 0.774000) | |
0.790000 0.000000 0.790000 ( 0.789000) | |
0.790000 0.010000 0.800000 ( 0.786000) | |
0.790000 0.000000 0.790000 ( 0.780000) | |
0.790000 0.000000 0.790000 ( 0.783000) | |
0.780000 0.000000 0.780000 ( 0.780000) | |
0.800000 0.000000 0.800000 ( 0.787000) | |
0.780000 0.010000 0.790000 ( 0.782000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jruby on OpenJDK 1.8 is twice as fast as 1.7
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-fred_2013_06_19_18_38-b00)
OpenJDK 64-Bit Server VM (build 25.0-b37, mixed mode)