Created
March 2, 2022 23:07
-
-
Save rlogwood/bc0d10a2a7c461f25bba5ec05372d622 to your computer and use it in GitHub Desktop.
Simple demonstration of ruby fiber scheduler
This file contains 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
# quick demo of fiber scheduling | |
# Ruby 3.1.1 | |
# see https://brunosutic.com/blog/ruby-fiber-scheduler | |
# see https://rubyapi.org/3.0/o/fiber/schedulerinterface | |
# see https://github.com/bruno-/fiber_scheduler_list | |
# using a default implementation of fiber_scheduler via | |
# gem install fiber_scheduler | |
require 'fiber_scheduler' | |
started_at = Time.now | |
Fiber.set_scheduler(FiberScheduler.new) | |
10_000.times do | |
Fiber.schedule do | |
sleep 2 | |
end | |
end | |
puts "Time to finish scheduling: #{(Time.now - started_at)}" | |
at_exit do | |
puts "Total Duration for 10,000 sleeps of 2 seconds: #{(Time.now - started_at)}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment