File: cons_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-- 660 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/list'

Benchmark.ips do |b|
  sml_list = Immutable::List[1]
  med_list = Immutable::List.empty
  100.times { |i| med_list = med_list.cons(i) }
  lrg_list = Immutable::List.empty
  10000.times { |i| lrg_list = lrg_list.cons(i) }

  b.report 'cons small' do |n|
    a = 0
    sml = sml_list
    while a < n
      sml = sml.cons(a)
      a += 1
    end
  end

  b.report 'cons medium' do |n|
    a = 0
    med = med_list
    while a < n
      med = med.cons(a)
      a += 1
    end
  end

  b.report 'cons large' do |n|
    a = 0
    lrg = lrg_list
    while a < n
      lrg = lrg.cons(a)
      a += 1
    end
  end
end