diff --git a/spec/benchmark-fifo.cr b/spec/benchmark-fifo.cr new file mode 100644 index 0000000..a6344b0 --- /dev/null +++ b/spec/benchmark-fifo.cr @@ -0,0 +1,35 @@ +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