-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
61 lines (49 loc) · 1.38 KB
/
Rakefile
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'bundler/gem_tasks'
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end
require 'rake/extensiontask'
task build: :compile
Rake::ExtensionTask.new('perf_counters') do |ext|
ext.lib_dir = 'lib/perf_counters'
end
task default: %i[clobber compile test]
task benchmark: %i[clobber compile] do
require 'benchmark/ips'
require 'perf_counters'
# TODO:
# - `x.stats = :bootstrap` seems to get frozen
# - investigate why results are not very consistent
Benchmark.ips do |x|
x.iterations = 3
x.report('no perf_counters') do |times|
(0..times).inject(:+)
end
x.report('using yield') do |times|
PerfCounters.measure(events: [Event::INSTRUCTIONS]) do
(0..times).inject(:+)
end
end
x.report('using yield (frozen array)') do |times|
PerfCounters.measure(events: [Event::INSTRUCTIONS].freeze) do
(0..times).inject(:+)
end
end
x.report('not using yield') do |times|
pc = PerfCounters::Measurement.new(events: [Event::INSTRUCTIONS])
pc.start
(0..times).inject(:+)
pc.stop
end
x.report('not using yield (frozen array)') do |times|
pc = PerfCounters::Measurement.new(events: [Event::INSTRUCTIONS].freeze)
pc.start
(0..times).inject(:+)
pc.stop
end
x.compare!
end
end