Skip to content

Instantly share code, notes, and snippets.

@byroot
Created December 27, 2023 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byroot/4c30bb81fe4e935b0df89ff217cb49ac to your computer and use it in GitHub Desktop.
Save byroot/4c30bb81fe4e935b0df89ff217cb49ac to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'benchmark-ips'
end
require 'benchmark/ips'
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 20
Benchmark.ips do |x|
x.report("gettime") do
500.times do |i|
Process.clock_gettime(Process::CLOCK_MONOTONIC) > deadline
end
end
x.report("modulo 100") do
500.times do |i|
next unless (i % 100) == 0
Process.clock_gettime(Process::CLOCK_MONOTONIC) > deadline
end
end
x.compare!(order: :baseline)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment