Created
March 25, 2024 20:38
-
-
Save gr33n7007h/7442fef406a3052df4aa64ef1f068357 to your computer and use it in GitHub Desktop.
Skynet Benchmark
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
# 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