Created
December 27, 2023 18:37
-
-
Save byroot/4c30bb81fe4e935b0df89ff217cb49ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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