Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created March 25, 2024 20:38
Show Gist options
  • Save gr33n7007h/7442fef406a3052df4aa64ef1f068357 to your computer and use it in GitHub Desktop.
Save gr33n7007h/7442fef406a3052df4aa64ef1f068357 to your computer and use it in GitHub Desktop.
Skynet Benchmark
# https://github.com/atemerev/skynet
module Skynet
module_function
def make_fiber(num, size, div)
Fiber.new do
Fiber.yield(num) if size == 1
fibers = (0...div).map do |i|
sub = num + i * (size / div)
make_fiber(sub, size / div, div)
end
Fiber.yield fibers.inject(0) { |acc, fib| acc + fib.resume }
end
end
end
r0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
r = Skynet.make_fiber(0, 1e6, 10).resume
r1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "Result: #{r} in #{r1 - r0} seconds."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment