Commit 553acf3b2a45f776b300e07fd0f0613417f993a5
- Diff rendering mode:
- inline
- side by side
|   | |||
| 1 | $:.unshift File.dirname(__FILE__) + "/../../lib" | ||
| 2 | require 'strokedb' | ||
| 3 | require 'benchmark' | ||
| 4 | include StrokeDB | ||
| 5 | |||
| 6 | puts "Serialization techniques" | ||
| 7 | |||
| 8 | len = 2_000 | ||
| 9 | array = (1..len).map{ [rand(len).to_s]*2 } | ||
| 10 | biglist = SimpleSkiplist.from_a(array) | ||
| 11 | dumped = biglist.marshal_dump | ||
| 12 | |||
| 13 | Benchmark.bm(17) do |x| | ||
| 14 | # First technique: to_a/from_a | ||
| 15 | GC.start | ||
| 16 | x.report("SimpleSkiplist#to_a ") do | ||
| 17 | biglist.to_a | ||
| 18 | biglist.to_a | ||
| 19 | biglist.to_a | ||
| 20 | biglist.to_a | ||
| 21 | biglist.to_a | ||
| 22 | end | ||
| 23 | GC.start | ||
| 24 | x.report("SimpleSkiplist.from_a ") do | ||
| 25 | SimpleSkiplist.from_a(array) | ||
| 26 | SimpleSkiplist.from_a(array) | ||
| 27 | SimpleSkiplist.from_a(array) | ||
| 28 | SimpleSkiplist.from_a(array) | ||
| 29 | SimpleSkiplist.from_a(array) | ||
| 30 | end | ||
| 31 | |||
| 32 | # Another technique: Marshal.dump | ||
| 33 | GC.start | ||
| 34 | x.report("SimpleSkiplist#marshal_dump ") do | ||
| 35 | biglist.marshal_dump | ||
| 36 | biglist.marshal_dump | ||
| 37 | biglist.marshal_dump | ||
| 38 | biglist.marshal_dump | ||
| 39 | biglist.marshal_dump | ||
| 40 | end | ||
| 41 | GC.start | ||
| 42 | x.report("SimpleSkiplist#marshal_load ") do | ||
| 43 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 44 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 45 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 46 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 47 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 48 | end | ||
| 49 | end | ||
| 50 | |||
| 51 | puts | ||
| 52 | puts "Find/insert techniques" | ||
| 53 | Benchmark.bm(42) do |x| | ||
| 54 | langs = [:C] if RUBY_PLATFORM !~ /java/ | ||
| 55 | langs = [:Java] if RUBY_PLATFORM =~ /java/ | ||
| 56 | SimpleSkiplist.with_optimizations(langs) do |lang| | ||
| 57 | GC.start | ||
| 58 | x.report("SimpleSkiplist#find 5000 #{lang}".ljust(32)) do | ||
| 59 | 1000.times do | ||
| 60 | key = rand(len).to_s | ||
| 61 | biglist.find(key) | ||
| 62 | biglist.find(key) | ||
| 63 | biglist.find(key) | ||
| 64 | biglist.find(key) | ||
| 65 | biglist.find(key) | ||
| 66 | end | ||
| 67 | end | ||
| 68 | GC.start | ||
| 69 | x.report("SimpleSkiplist#insert 5000 #{lang}".ljust(32)) do | ||
| 70 | 1000.times do | ||
| 71 | key = rand(len).to_s | ||
| 72 | biglist.insert(key, key) | ||
| 73 | key = rand(len).to_s | ||
| 74 | biglist.insert(key, key) | ||
| 75 | key = rand(len).to_s | ||
| 76 | biglist.insert(key, key) | ||
| 77 | key = rand(len).to_s | ||
| 78 | biglist.insert(key, key) | ||
| 79 | key = rand(len).to_s | ||
| 80 | biglist.insert(key, key) | ||
| 81 | end | ||
| 82 | end | ||
| 83 | end | ||
| 84 | end |
|   | |||
| 1 | $:.unshift File.dirname(__FILE__) + "/../../lib" | ||
| 2 | require 'strokedb' | ||
| 3 | require 'benchmark' | ||
| 4 | include StrokeDB | ||
| 5 | |||
| 6 | puts "Serialization techniques" | ||
| 7 | |||
| 8 | len = 2_000 | ||
| 9 | array = (1..len).map{ [rand(len).to_s]*2 } | ||
| 10 | biglist = SimpleSkiplist.from_a(array) | ||
| 11 | dumped = biglist.marshal_dump | ||
| 12 | |||
| 13 | Benchmark.bm(17) do |x| | ||
| 14 | # First technique: to_a/from_a | ||
| 15 | GC.start | ||
| 16 | x.report("SimpleSkiplist#to_a ") do | ||
| 17 | biglist.to_a | ||
| 18 | biglist.to_a | ||
| 19 | biglist.to_a | ||
| 20 | biglist.to_a | ||
| 21 | biglist.to_a | ||
| 22 | end | ||
| 23 | GC.start | ||
| 24 | x.report("SimpleSkiplist.from_a ") do | ||
| 25 | SimpleSkiplist.from_a(array) | ||
| 26 | SimpleSkiplist.from_a(array) | ||
| 27 | SimpleSkiplist.from_a(array) | ||
| 28 | SimpleSkiplist.from_a(array) | ||
| 29 | SimpleSkiplist.from_a(array) | ||
| 30 | end | ||
| 31 | |||
| 32 | # Another technique: Marshal.dump | ||
| 33 | GC.start | ||
| 34 | x.report("SimpleSkiplist#marshal_dump ") do | ||
| 35 | biglist.marshal_dump | ||
| 36 | biglist.marshal_dump | ||
| 37 | biglist.marshal_dump | ||
| 38 | biglist.marshal_dump | ||
| 39 | biglist.marshal_dump | ||
| 40 | end | ||
| 41 | GC.start | ||
| 42 | x.report("SimpleSkiplist#marshal_load ") do | ||
| 43 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 44 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 45 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 46 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 47 | SimpleSkiplist.allocate.marshal_load(dumped.dup) | ||
| 48 | end | ||
| 49 | end | ||
| 50 | |||
| 51 | puts | ||
| 52 | puts "Find/insert techniques" | ||
| 53 | Benchmark.bm(42) do |x| | ||
| 54 | langs = [:C] if RUBY_PLATFORM !~ /java/ | ||
| 55 | langs = [:Java] if RUBY_PLATFORM =~ /java/ | ||
| 56 | SimpleSkiplist.with_optimizations(langs) do |lang| | ||
| 57 | GC.start | ||
| 58 | x.report("SimpleSkiplist#find 5000 #{lang}".ljust(32)) do | ||
| 59 | 1000.times do | ||
| 60 | key = rand(len).to_s | ||
| 61 | biglist.find(key) | ||
| 62 | biglist.find(key) | ||
| 63 | biglist.find(key) | ||
| 64 | biglist.find(key) | ||
| 65 | biglist.find(key) | ||
| 66 | end | ||
| 67 | end | ||
| 68 | GC.start | ||
| 69 | x.report("SimpleSkiplist#insert 5000 #{lang}".ljust(32)) do | ||
| 70 | 1000.times do | ||
| 71 | key = rand(len).to_s | ||
| 72 | biglist.insert(key, key) | ||
| 73 | key = rand(len).to_s | ||
| 74 | biglist.insert(key, key) | ||
| 75 | key = rand(len).to_s | ||
| 76 | biglist.insert(key, key) | ||
| 77 | key = rand(len).to_s | ||
| 78 | biglist.insert(key, key) | ||
| 79 | key = rand(len).to_s | ||
| 80 | biglist.insert(key, key) | ||
| 81 | end | ||
| 82 | end | ||
| 83 | end | ||
| 84 | end |

