File: at_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 (39 lines) | stat: -rw-r--r-- 744 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
38
39
require 'benchmark/ips'
require 'immutable/list'

Benchmark.ips do |b|
  sml_list = Immutable::List[1]
  # med_list = Immutable.iterate(1, &:next).take(100)
  # lrg_list = Immutable.iterate(1, &:next).take(10000)
  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 'at small' do |n|
    a = 0
    x = 0
    while a < n
      x = sml_list.at(0)
      a += 1
    end
  end

  b.report 'at medium' do |n|
    a = 0
    x = 0
    while a < n
      x = med_list.at(99)
      a += 1
    end
  end

  b.report 'at large' do |n|
    a = 0
    x = 0
    while a < n
      x = lrg_list.at(9999)
      a += 1
    end
  end
end