From b0e3d8c5e8fa5d6684a258621267aca6e8f5b3cb Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Sun, 26 May 2024 05:42:10 +0200 Subject: [PATCH] Benchmark fifo. --- spec/benchmark-fifo.cr | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/benchmark-fifo.cr 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