Skip to content

Instantly share code, notes, and snippets.

@sam
Created August 10, 2012 21:27
Show Gist options
  • Save sam/3318138 to your computer and use it in GitHub Desktop.
Save sam/3318138 to your computer and use it in GitHub Desktop.
Map Benchmarks under JRuby 1.7.0.preview2
require "java"
hash_map = {}
java_import com.hazelcast.core.Hazelcast
at_exit { Hazelcast.shutdown_all }
hazel_map = Hazelcast.get_map "benchmark"
java_import org.infinispan.Cache
java_import org.infinispan.manager.DefaultCacheManager
infinispan_map = DefaultCacheManager.new.get_cache
require "benchmark"
def iterate_set(map)
10_000.times do |i|
map[i.to_s] = i
end
end
def iterate_get(map)
10_000.times do |i|
map[i.to_s].to_s
end
end
Benchmark::bmbm do |x|
x.report("Hash:set") do
iterate_set hash_map
end
x.report("Hazelcast:set") do
iterate_set hazel_map
end
x.report("Infinispan:set") do
iterate_set infinispan_map
end
x.report("Hash:get") do
iterate_get hash_map
end
x.report("Hazelcast:get") do
iterate_get hazel_map
end
x.report("Infinispan:get") do
iterate_get infinispan_map
end
end
### 1,000 Sets
Rehearsal ----------------------------------------------
Hash 0.040000 0.000000 0.040000 ( 0.027000)
Hazelcast 1.510000 0.160000 1.670000 ( 1.348000)
Infinispan 0.150000 0.000000 0.150000 ( 0.125000)
------------------------------------- total: 1.860000sec
user system total real
Hash 0.030000 0.000000 0.030000 ( 0.033000)
Hazelcast 1.820000 0.170000 1.990000 ( 1.650000)
Infinispan 0.090000 0.000000 0.090000 ( 0.094000)
### 10,000 Sets and Gets
Rehearsal --------------------------------------------------
Hash:set 0.270000 0.000000 0.270000 ( 0.208000)
Hazelcast:set 37.440000 1.750000 39.190000 ( 37.104000)
Infinispan:set 0.840000 0.020000 0.860000 ( 0.566000)
Hash:get 0.290000 0.010000 0.300000 ( 0.172000)
Hazelcast:get 35.660000 1.210000 36.870000 ( 35.689000)
Infinispan:get 0.250000 0.000000 0.250000 ( 0.154000)
---------------------------------------- total: 77.740000sec
user system total real
Hash:set 0.030000 0.000000 0.030000 ( 0.013000)
Hazelcast:set 67.960000 2.460000 70.420000 ( 69.195000)
Infinispan:set 0.110000 0.000000 0.110000 ( 0.109000)
Hash:get 0.020000 0.000000 0.020000 ( 0.016000)
Hazelcast:get 34.390000 1.030000 35.420000 ( 34.899000)
Infinispan:get 0.020000 0.000000 0.020000 ( 0.022000)
### 10,000 Sets and Gets (repeated x2 to see if Gets are faster on second access)
Rehearsal --------------------------------------------------
Hash:set 0.280000 0.010000 0.290000 ( 0.230000)
Hazelcast:set 39.270000 2.320000 41.590000 ( 41.196000)
Infinispan:set 1.380000 0.050000 1.430000 ( 0.936000)
Hash:get 0.320000 0.000000 0.320000 ( 0.212000)
Hazelcast:get 36.150000 1.430000 37.580000 ( 37.922000)
Infinispan:get 0.440000 0.020000 0.460000 ( 0.305000)
Hash:get 0.010000 0.000000 0.010000 ( 0.011000)
Hazelcast:get 34.710000 1.360000 36.070000 ( 36.720000)
Infinispan:get 0.020000 0.000000 0.020000 ( 0.019000)
--------------------------------------- total: 117.770000sec
user system total real
Hash:set 0.040000 0.000000 0.040000 ( 0.039000)
Hazelcast:set 69.560000 2.890000 72.450000 ( 75.160000)
Infinispan:set 0.120000 0.000000 0.120000 ( 0.136000)
Hash:get 0.020000 0.000000 0.020000 ( 0.010000)
Hazelcast:get 34.520000 1.370000 35.890000 ( 37.052000)
Infinispan:get 0.020000 0.000000 0.020000 ( 0.020000)
Hash:get 0.010000 0.000000 0.010000 ( 0.011000)
Hazelcast:get 34.500000 1.370000 35.870000 ( 36.757000)
Infinispan:get 0.020000 0.000000 0.020000 ( 0.019000)
@sam
Copy link
Author

sam commented Aug 10, 2012

NOTE: This is only for 1,000 entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment