File: put_bench.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 690 bytes parent folder | download
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
require 'benchmark/ips'
require 'immutable/hash'

Benchmark.ips do |b|
  sml_hash = Immutable::Hash[1 => 1]
  med_hash = Immutable::Hash.empty
  1_000.times { |i| med_hash = med_hash.put(i, i) }
  lrg_hash = Immutable::Hash.empty
  1_000_000.times { |i| lrg_hash = lrg_hash.put(i, i) }

  b.report 'put value' do |n|
    a = 0
    sml = sml_hash
    while a < n
      sml = sml.put(a, a)
      a += 1
    end
  end

  b.report 'put value medium' do |n|
    a = 0
    med = med_hash
    while a < n
      med = med.put(a, a)
      a += 1
    end
  end

  b.report 'put value large' do |n|
    a = 0
    lrg = lrg_hash
    while a < n
      lrg = lrg.put(a, a)
      a += 1
    end
  end
end