Sha256: 913fa9501f3ec372d7779500586db6481d527d42c4682377026731ffc9ec0d22

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

# 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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stack_frames-0.1.3 benchmark.rb
stack_frames-0.1.2 benchmark.rb
stack_frames-0.1.1 benchmark.rb
stack_frames-0.1.0 benchmark.rb