-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbenchmark.rb
More file actions
47 lines (44 loc) · 1.18 KB
/
benchmark.rb
File metadata and controls
47 lines (44 loc) · 1.18 KB
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
# frozen_string_literal: true
require 'bundler/setup'
require 'benchmark/ips'
require 'stack_frames'
STACK_FRAMES_CALLER_BUFFER = StackFrames::Buffer.new(2)
STACK_FRAMES_BUFFER = StackFrames::Buffer.new(2048)
LOCK = Mutex.new
Thread.current.thread_variable_set(:stack_frames_buffer, STACK_FRAMES_BUFFER)
Benchmark.ips do |bench|
bench.report("caller(1, 1)") do
caller(1, 1).first
end
bench.report("caller_locations(1, 1)") do
caller_locations(1, 1).first.path
end
bench.report("stack_frames caller frame") do
buffer = STACK_FRAMES_CALLER_BUFFER
buffer.capture
buffer[1].path
end
bench.report("caller") do
caller.first
end
bench.report("caller_locations") do
caller_locations.first.path
end
bench.report("stack_frames capture stack") do
buffer = STACK_FRAMES_BUFFER
buffer.capture
buffer[1].path
end
bench.report("stack_frames synchronized capture") do
LOCK.synchronize do
buffer = STACK_FRAMES_BUFFER
buffer.capture
buffer[1].path
end
end
bench.report("stack_frames thread-local capture") do
buffer = Thread.current.thread_variable_get(:stack_frames_buffer)
buffer.capture
buffer[1].path
end
end