require "benchmark" require "../src/fifo.cr" def add(fifo : FIFO(Int32) | EfficientFIFO(Int32), nb : UInt32) i = 0 while i < nb fifo << i i += 1 end end class Context class_property nb_values : UInt32 = 100_000 class_property fifo_size : UInt32 = 10_000 end if nb_values = ENV["NBVAL"]? Context.nb_values = nb_values.to_u32 end if fifo_size = ENV["FIFOSIZE"]? Context.fifo_size = fifo_size.to_u32 end Benchmark.ips do |x| x.report("adding #{Context.nb_values} values, FIFO limited to #{Context.fifo_size}") do fifo = FIFO(Int32).new Context.fifo_size add fifo, Context.nb_values end x.report("adding #{Context.nb_values} values, EfficientFIFO limited to #{Context.fifo_size}") do fifo = EfficientFIFO(Int32).new Context.fifo_size add fifo, Context.nb_values end end