Skip to content

Commit

Permalink
Added emf2svg benchmarking (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx authored Nov 15, 2023
1 parent 216285d commit 148789d
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 31 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ jobs:
- name: Run the default task
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
- name: Check "Hello, world" benchmarking
run: bundle exec exe/tebako-benchmarking measure -c 'ruby tests/simple-test/simple-test-run.rb' -r 1 10 100

- name: Check coradoc gem benchmarking
run: bundle exec exe/tebako-benchmarking measure -c 'ruby tests/coradoc-test/coradoc-test-run.rb' -r 1 10 100

- name: Check emf2svg gem benchmarking
run: bundle exec exe/tebako-benchmarking measure -c 'ruby tests/emf2svg-test/emf2svg-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"
21 changes: 4 additions & 17 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
= Tebako-benchmarking

== Benchmarking tool for tebako packages
= Tebako benchmarking

Tebako (https://github.com/tamatebako/tebako) is an executable packager.
tebako-benchmarking gem provides a tool to measure performance of the packages created with tebako.

== Results

Benchmarking results are available at results folder.

== Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

== Contributing
This repository contains scripts that are used for tebako benchmarking and benchmarking results which are available
at results folder at https://github.com/tamatebako/tebako-benchmarking/blob/main/results/RESULTS.adoc

Bug reports and pull requests are welcome on GitHub at https://github.com/tamatebako/tebako-benchmarking.
This is work area and does not not pretend to have a production quality or be reusable in any way.
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
35 changes: 34 additions & 1 deletion results/RESULTS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This is because the runtime library is served from an in-memory file system with
In short runs, Tebako loses because the package includes many files and components that are not used by the application, but are still loaded into memory.
This creates a penalty of 0.3 seconds, which is however negligible in runs experiments.

== coradoc Gem
== coradoc gem

https://rubygems.org/gems/coradoc

Expand Down Expand Up @@ -69,6 +69,39 @@ Also the test shows that there is no difference in code execution between native

image::coradoc-benchmarking.jpg[coradoc benchmarking results]

== emf2svg gem

https://rubygems.org/gems/emf2svg

```
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
```

image::emf2svg-benchmarking.jpg[emf2svg benchmarking results]

== Execution environment

```
Expand Down
Binary file modified results/img/coradoc-benchmarking.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added results/img/emf2svg-benchmarking.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 148789d

Please sign in to comment.