Skip to content

Commit

Permalink
Accurate visual benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpclark committed Feb 24, 2017
1 parent ff39d8d commit d502b87
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ Or install it yourself as:

**MAC USERS:** At the moment Mac users need to install the extension manualy. Go to the gem directory and run `cargo build --release` . There is an issue opened for this and I'm looking for people who have Macs to help on this.

## Visual Benchmarks

Benchmarks in Faster Path now produce visual graph charts of performance improvements.
When you run `rake bench` the graph art will be placed in `doc/graph/`. Here's the performance
improvement result for the `chop_basename` method.

![Visual Benchmark](https://raw.githubusercontent.com/danielpclark/faster_path/master/assets/chop_basename_benchmark.jpg "Visual Benchmark")

## Usage

Current methods implemented:
Expand Down
Binary file added assets/chop_basename_benchmark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/benches/absolute_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def bench_rust_absolute?
FasterPath.absolute?("goodbye")
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_absolute?
Expand All @@ -23,5 +24,6 @@ def bench_ruby_absolute?
Pathname.new("goodbye").absolute?
end
end
TIMER[__FILE__].ruby.mark
end
end
2 changes: 2 additions & 0 deletions test/benches/add_trailing_separator_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def bench_rust_add_trailing_separator
FasterPath.add_trailing_separator('/hello/world/')
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_add_trailing_separator
Expand All @@ -23,6 +24,7 @@ def bench_ruby_add_trailing_separator
Pathname.allocate.send(:add_trailing_separator, '/hello/world/')
end
end
TIMER[__FILE__].ruby.mark
end
end

2 changes: 2 additions & 0 deletions test/benches/basename_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def bench_rust_basename
FasterPath.basename('/home/gumby/work/ruby.rb', '.*')
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_basename
Expand All @@ -25,5 +26,6 @@ def bench_ruby_basename
File.basename('/home/gumby/work/ruby.rb', '.*')
end
end
TIMER[__FILE__].ruby.mark
end
end
2 changes: 2 additions & 0 deletions test/benches/chop_basename_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def bench_rust_chop_basename
FasterPath.chop_basename ""
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_chop_basename
Expand All @@ -25,5 +26,6 @@ def bench_ruby_chop_basename
Pathname.new("").send :chop_basename, ""
end
end
TIMER[__FILE__].ruby.mark
end
end
2 changes: 2 additions & 0 deletions test/benches/directory_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def bench_rust_directory?
FasterPath.directory?("goodbye")
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_directory?
Expand All @@ -23,5 +24,6 @@ def bench_ruby_directory?
Pathname.new("goodbye").directory?
end
end
TIMER[__FILE__].ruby.mark
end
end
2 changes: 2 additions & 0 deletions test/benches/dirname_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def bench_ruby_dirname
File.dirname "."
end
end
TIMER[__FILE__].rust.mark
end

def bench_rust_dirname
Expand All @@ -25,5 +26,6 @@ def bench_rust_dirname
FasterPath.dirname "."
end
end
TIMER[__FILE__].ruby.mark
end
end
2 changes: 2 additions & 0 deletions test/benches/entries_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def bench_rust_entries
FasterPath.entries("src")
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_entries
Expand All @@ -27,5 +28,6 @@ def bench_ruby_entries
Pathname.new("src").entries
end
end
TIMER[__FILE__].ruby.mark
end
end
2 changes: 2 additions & 0 deletions test/benches/extname_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def bench_rust_extname
CASES.each { |path| FasterPath.extname(path) }
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_extname
Expand All @@ -30,5 +31,6 @@ def bench_ruby_extname
CASES.each { |path| File.extname(path) }
end
end
TIMER[__FILE__].ruby.mark
end
end
2 changes: 2 additions & 0 deletions test/benches/has_trailing_separator_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def bench_rust_has_trailing_separator
FasterPath.has_trailing_separator? 'hello/'
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_has_trailing_separator
Expand All @@ -23,5 +24,6 @@ def bench_ruby_has_trailing_separator
Pathname.allocate.send :has_trailing_separator?, 'hello/'
end
end
TIMER[__FILE__].ruby.mark
end
end
2 changes: 2 additions & 0 deletions test/benches/relative_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def bench_rust_relative?
FasterPath.relative?("goodbye")
end
end
TIMER[__FILE__].rust.mark
end

def bench_ruby_relative?
Expand All @@ -23,5 +24,6 @@ def bench_ruby_relative?
Pathname.new("goodbye").relative?
end
end
TIMER[__FILE__].ruby.mark
end
end
6 changes: 3 additions & 3 deletions test/benchmark_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def teardown file
if TIMER[file].rust.time? && TIMER[file].ruby.time?
# print graph
g = Gruff::Line.new
g.title = File.basename(file)
g.title = File.basename(file).to_s[0..-4].split('_').map(&:capitalize).join(' ')
g.labels = (self.instance_exec{defined?(self.class.bench_range) ? self.class.bench_range : nil} || BenchmarkHelper.bench_range).
each.with_index.
reduce({}) {|h,(v,i)|
h[i]=v;h
}
h[i+1]=v;h
}.merge({0 => 0})

g.data(:ruby, TIMER[file].ruby.times.unshift(0))
g.data(:rust, TIMER[file].rust.times.unshift(0))
Expand Down

0 comments on commit d502b87

Please sign in to comment.