Skip to content

Commit

Permalink
Added emf2svg benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Nov 15, 2023
1 parent 216285d commit 18b6aaf
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
run: bundle exec exe/tebako-benchmarking measure -c 'ruby tests/simple-test/simple-test-run.rb' -r 1 10 100
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ gemspec
gem "rake", "~> 13.0"

gem "rubocop", "~> 1.21"

gem "vectory", git: "https://github.com/metanorma/vectory.git"
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
72 changes: 61 additions & 11 deletions lib/tebako/benchmarking/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = {}

Expand Down Expand Up @@ -94,6 +115,35 @@ def preprocess
nil
end

def print_comparison_headers(cmd1, cmd2)
l1 = cmd1.length
l2 = cmd2.length

puts

header0 = format("%<key>-15s| %<value1>-#{l1}s| %<value2>-#{l2}s",
key: "Repetitions",
value1: "Total time",
value2: "Total time")
puts header0
puts format("%<key>-15s| %<value1>-#{l1}s| %<value2>-#{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("%<key>-15s| %<value1>-#{cmd1.length}s| %<value2>-#{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("%<key>-15s %<value>-15s", key: "Repetitions", value: "Total time")
separator = "-" * header.length
Expand Down
Binary file modified results/raw/results.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions tebako-benchmarking.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions tests/emf2svg-test/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "emf2svg", "~> 1.4.3"
26 changes: 26 additions & 0 deletions tests/emf2svg-test/emf2svg-test-run.rb
Original file line number Diff line number Diff line change
@@ -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
Binary file added tests/emf2svg-test/fixtures/img.emf
Binary file not shown.

0 comments on commit 18b6aaf

Please sign in to comment.