Sha256: 6679be3731f20d63cb4e6ef39f798e430a212409f29026e40c6a2f57a55977af
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
# frozen_string_literal: true require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'uringmachine', path: '..' gem 'benchmark-ips' end require 'benchmark/ips' require 'uringmachine' ITERATIONS = 1000 $machine = UringMachine.new def run_snooze count = 0 main = Fiber.current f1 = Fiber.new do loop do count += 1 if count == ITERATIONS $machine.schedule(main, nil) break else $machine.snooze end end end f2 = Fiber.new do loop do count += 1 if count == ITERATIONS $machine.schedule(main, nil) break else $machine.snooze end end end $machine.schedule(f1, nil) $machine.schedule(f2, nil) $machine.yield end def run_raw_transfer count = 0 main = Fiber.current f2 = nil f1 = Fiber.new do loop do count += 1 if count == ITERATIONS main.transfer(nil) break else f2.transfer(nil) end end end f2 = Fiber.new do loop do count += 1 if count == ITERATIONS main.transfer(nil) break else f1.transfer(nil) end end end f1.transfer(nil) end bm = Benchmark.ips do |x| x.config(:time => 5, :warmup => 2) x.report("snooze") { run_snooze } x.report("raw transfer") { run_raw_transfer } x.compare! end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
uringmachine-0.5.1 | examples/bm_snooze.rb |
uringmachine-0.5 | examples/bm_snooze.rb |