#!/usr/bin/env ruby # frozen_string_literal: true # Single-query scaling benchmark: runs `kgrid query 10^e` for each exponent, # one process at a time, and prints a CSV line per run. # # scaling.rb FROM_EXP TO_EXP [extra kgrid flags...] # # Example: scripts/scaling.rb 4 14 --mem-limit 4 BIN = File.expand_path('../target/release/kgrid', __dir__) def field(out, name) line = out.lines.find { |l| l.start_with?(name) } line&.split(':', 2)&.last&.strip end def run(exp, flags) k = 10**exp out = IO.popen([BIN, 'query', k.to_s, '--poly-file', File::NULL, *flags], err: %i[child out], &:read) status = $?.success? ? 'ok' : 'FAIL' time = field(out, 'time') [exp, k, field(out, 'perimeter'), field(out, 'vertices'), field(out, 'certified')&.split&.first, field(out, 'check')&.split&.first, time&.[](/[\d.]+ s/), time&.[](/RSS [\d.]+ MB/), status] end from_exp, to_exp, *flags = ARGV abort('usage: scaling.rb FROM_EXP TO_EXP [kgrid flags]') unless from_exp && to_exp puts 'exp,k,perimeter,vertices,certified,check,time,peak_rss,exit' (Integer(from_exp)..Integer(to_exp)).each do |e| puts run(e, flags).join(',') $stdout.flush end