diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4f39df6..a19805c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,4 +28,4 @@ jobs: run: bundle exec rake - name: Try "Hello, world" benchmarking - run: bundle exec exe/tebako-benchmarking measure -p 'ruby tests/simple-test/simple-test-run.rb' -r 1 10 100 \ No newline at end of file + run: bundle exec exe/tebako-benchmarking measure -c 'ruby tests/simple-test/simple-test-run.rb' -r 1 10 100 diff --git a/Gemfile b/Gemfile index 2d727a2..6432854 100644 --- a/Gemfile +++ b/Gemfile @@ -33,3 +33,5 @@ gemspec gem "rake", "~> 13.0" gem "rubocop", "~> 1.21" + +gem "vectory", git: "https://github.com/metanorma/vectory.git" diff --git a/README.adoc b/README.adoc index 3744de7..f4f5d61 100644 --- a/README.adoc +++ b/README.adoc @@ -7,7 +7,7 @@ tebako-benchmarking gem provides a tool to measure performance of the packages c == Results -Benchmarking results are available at results folder. +Benchmarking results are available at results folder at https://github.com/tamatebako/tebako-benchmarking/blob/main/results/RESULTS.adoc == Development diff --git a/lib/tebako/benchmarking/cli.rb b/lib/tebako/benchmarking/cli.rb index f49dc77..92d408b 100755 --- a/lib/tebako/benchmarking/cli.rb +++ b/lib/tebako/benchmarking/cli.rb @@ -40,20 +40,35 @@ module Benchmarking class Cli < Thor package_name "Tebako benchmarking" - desc "measure", "Measure execution metrics of a Tebako package" - method_option :package, type: :string, aliases: "-p", required: true, - desc: "Tebako package to benchmark" - - method_option :repetitions, type: :array, aliases: "-r", required: true, - desc: "Repetitions to run (array of positive integers)", default: ["1"] - method_option :verbose, type: :boolean, aliases: "-v", default: false, - desc: "Print benchmarking data for each repetition value" + class_option :repetitions, type: :array, aliases: "-r", required: false, + desc: "Repetitions to run (array of positive integers)", default: ["1"] + class_option :verbose, type: :boolean, aliases: "-v", default: false, + desc: "Print benchmarking data for each repetition value" + + desc "compare", "Compare execution metrics of two commands" + method_option :first, type: :string, required: true, aliases: "-f", + desc: "The first command" + method_option :second, type: :string, required: true, aliases: "-s", + desc: "The second command" + + def compare + exit 1 if (repetitions = preprocess).nil? + cmd1 = options["first"] + cmd2 = options["second"] + exit 1 if repetitions[0] != 1 && !(Tebako::Benchmarking.test_cmd(cmd1) && Tebako::Benchmarking.test_cmd(cmd2)) + + do_compare(cmd1, cmd2, repetitions, options["verbose"]) + end + + desc "measure", "Measure execution metrics for a command" + method_option :cmd, type: :string, aliases: "-c", required: true, + desc: "Command to benchmark" def measure exit 1 if (repetitions = preprocess).nil? - package = options["package"] - exit 1 unless repetitions[0] == 1 || Tebako::Benchmarking.test_cmd(package) + cmd = options["cmd"] + exit 1 unless repetitions[0] == 1 || Tebako::Benchmarking.test_cmd(cmd) - mea = iterate(package, repetitions, options["verbose"]) + mea = iterate(cmd, repetitions, options["verbose"]) print_results(mea) end @@ -64,6 +79,12 @@ def self.exit_on_failure? end # rubocop:disable Metrics/BlockLength no_commands do + def do_compare(cmd1, cmd2, repetitions, verbose) + mea1 = iterate(cmd1, repetitions, verbose) + mea2 = iterate(cmd2, repetitions, verbose) + print_comparison(cmd1, cmd2, mea1, mea2) + end + def iterate(package, repetitions, verbose) mea = {} @@ -94,6 +115,35 @@ def preprocess nil end + def print_comparison_headers(cmd1, cmd2) + l1 = cmd1.length + l2 = cmd2.length + + puts + + header0 = format("%-15s| %-#{l1}s| %-#{l2}s", + key: "Repetitions", + value1: "Total time", + value2: "Total time") + puts header0 + puts format("%-15s| %-#{l1}s| %-#{l2}s", + key: "", + value1: cmd1.to_s, + value2: cmd2.to_s) + + puts "-" * header0.length + end + + def print_comparison(cmd1, cmd2, mea1, mea2) + rows = mea1.keys.zip(mea1.values, mea2.values).map do |r, m1, m2| + format("%-15s| %-#{cmd1.length}s| %-#{cmd2.length}s", key: r, value1: m1["total"], + value2: m2["total"]) + end + + puts print_comparison_headers(cmd1, cmd2) + puts rows + end + def print_results(mea) header = format("%-15s %-15s", key: "Repetitions", value: "Total time") separator = "-" * header.length diff --git a/results/raw/results.xlsx b/results/raw/results.xlsx index 30f8b5c..4e42b3c 100644 Binary files a/results/raw/results.xlsx and b/results/raw/results.xlsx differ diff --git a/tebako-benchmarking.gemspec b/tebako-benchmarking.gemspec index ae70361..2cebebf 100644 --- a/tebako-benchmarking.gemspec +++ b/tebako-benchmarking.gemspec @@ -58,6 +58,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "coradoc", "~> 0.1.0" + spec.add_dependency "emf2svg", "~> 1.4.3" spec.add_dependency "tebako", "~> 0.5.5" spec.add_dependency "tebako-runtime", "~> 0.2.1" spec.add_dependency "thor", "~> 1.2" diff --git a/tests/emf2svg-test/Gemfile b/tests/emf2svg-test/Gemfile new file mode 100644 index 0000000..af7068a --- /dev/null +++ b/tests/emf2svg-test/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "emf2svg", "~> 1.4.3" diff --git a/tests/emf2svg-test/emf2svg-test-run.rb b/tests/emf2svg-test/emf2svg-test-run.rb new file mode 100755 index 0000000..ef76e88 --- /dev/null +++ b/tests/emf2svg-test/emf2svg-test-run.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "tempfile" + +puts "Hello! This is emf2svg benchmarking test." + +if (argv = ARGV).empty? + puts "No arguments given" + exit(1) +end + +if argv[0].to_i < 1 + puts "Argument must be a positive integer" + exit(1) +end + +argv[0].to_i.times do + require "emf2svg" + + svg = Emf2svg.from_file(File.join(__dir__, "fixtures", "img.emf")) + + Tempfile.create(["output", ".svg"]) do |tempfile| + tempfile.write(svg) + puts "SVG written to #{tempfile.path}" + end +end diff --git a/tests/emf2svg-test/fixtures/img.emf b/tests/emf2svg-test/fixtures/img.emf new file mode 100644 index 0000000..e93c33c Binary files /dev/null and b/tests/emf2svg-test/fixtures/img.emf differ