From e827fc4c2728a2538e0fc8b050adac96ff601c67 Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez Date: Sat, 19 Aug 2023 16:37:33 -0500 Subject: [PATCH] Expand the demo to make testing / benchmarking easier --- example/demo.cr | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/example/demo.cr b/example/demo.cr index f4f73fa..91acbda 100644 --- a/example/demo.cr +++ b/example/demo.cr @@ -1,10 +1,30 @@ -require "../src/alys" - +require "option_parser" require "uuid" +require "../src/alys" + class X + def initialize(@quiet : Bool) + end + def finalize - puts 123 + puts 123 if !@quiet + end +end + +sleep_ms = 1000 +iterations = 0 +quiet = false + +OptionParser.parse do |parser| + parser.on "--sleep=MS", "Sleep duration" do |value| + sleep_ms = value.to_i + end + parser.on "--iterations=ITERATIONS", "Iteration count" do |value| + iterations = value.to_i + end + parser.on "--quiet", "Be quiet" do + quiet = true end end @@ -13,13 +33,13 @@ Alys.setup_from_env objs = [] of UUID -loop do - X.new +(0..(iterations > 0 ? iterations : nil)).each do |_| + X.new quiet ptr = GC.malloc 10 ptr = GC.realloc ptr, 20 GC.free ptr Regex.new "abc" objs << UUID.random GC.collect - sleep 1.seconds + sleep sleep_ms.milliseconds unless sleep_ms <= 0 end -- 2.45.2