summaryrefslogtreecommitdiff
path: root/bench/bench_buffer_alloc.rb
blob: 6314b6328d9b3f3b6691d0dd1ec4e14a431358c4 (plain)
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
40
41
42
43
44
45
require_relative 'bench_helper'

module BenchBufferAlloc
  iter = ITER

  puts "Benchmark Buffer.new(:int, 1, true)) performance, #{iter}x"
  10.times {
    puts Benchmark.measure {
      i = 0; while i < iter
        FFI::Buffer.new(:int, 1, true)
        i += 1
      end
    }
  }

  puts "Benchmark Buffer.alloc_out(:int, 1, true)) performance, #{iter}x"
  10.times {
    puts Benchmark.measure {
      i = 0; while i < iter
        FFI::Buffer.new_out(:int, 1, true)
        i += 1
      end
    }
  }

  puts "Benchmark Buffer.new(4, 1, true)) performance, #{iter}x"
  10.times {
    puts Benchmark.measure {
      i = 0; while i < iter
        FFI::Buffer.new(4, 1, true)
        i += 1
      end
    }
  }

  puts "Benchmark Buffer.new(256, 1, true)) performance, #{iter}x"
  10.times {
    puts Benchmark.measure {
      i = 0; while i < iter
        FFI::Buffer.new(256, 1, true)
        i += 1
      end
    }
  }
end