diffbench 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,13 +3,12 @@
3
3
  Diffbench is tool the I end up during many many performance patches to:
4
4
 
5
5
  * Rails
6
- * ActiveRecord
7
- * ActiveModel
8
- * ActiveSupport
9
- * Mail
6
+ * ActiveRecord - [#5467](https://github.com/rails/rails/pull/5467)
7
+ * ActiveModel - [#5431](https://github.com/rails/rails/pull/5431)
8
+ * ActiveSupport - [#4493](https://github.com/rails/rails/pull/4493)
9
+ * Mail - [#396](https://github.com/mikel/mail/pull/369), [#366](https://github.com/mikel/mail/pull/366)
10
10
 
11
- It runs a same benchmark code before and after applying a patch
12
- TODO links to original PRs
11
+ It runs a same benchmark code before and after applying a patch.
13
12
 
14
13
  ## Installation
15
14
 
@@ -32,10 +31,14 @@ DiffBench.bm do
32
31
  Mail::Header.new("X-Subscriber: 1111\n"* 1000)
33
32
  end
34
33
  report("headers parsing when tiny") do
35
- Mail::Header.new("X-Subscriber: 1111\n"* 10)
34
+ 10.times do
35
+ Mail::Header.new("X-Subscriber: 1111\n"* 10)
36
+ end
36
37
  end
37
38
  report("headers parsing when empty") do
38
- Mail::Header.new("")
39
+ 100.times do
40
+ Mail::Header.new("")
41
+ end
39
42
  end
40
43
  end
41
44
  ```
@@ -50,4 +53,26 @@ If the working tree is dirty than diffbench will run benchmark against dirty and
50
53
  If the working tree is not dirty than diffbench will run benchmark against current HEAD and commit previous to HEAD.
51
54
 
52
55
 
56
+ Output:
57
+
58
+ ```
59
+ Running benchmark with current working tree
60
+ Checkout HEAD^
61
+ Running benchmark with HEAD^
62
+ Checkout to previous HEAD again
63
+
64
+ user system total real
65
+ ----------------------------------headers parsing when long
66
+ After patch: 0.100000 0.000000 0.100000 ( 0.089926)
67
+ Before patch: 0.700000 0.000000 0.700000 ( 0.697444)
68
+
69
+ ----------------------------------headers parsing when tiny
70
+ After patch: 0.000000 0.000000 0.000000 ( 0.009930)
71
+ Before patch: 0.020000 0.000000 0.020000 ( 0.024283)
72
+
73
+ ---------------------------------headers parsing when empty
74
+ After patch: 0.010000 0.000000 0.010000 ( 0.002160)
75
+ Before patch: 0.000000 0.000000 0.000000 ( 0.002354)
76
+ ```
77
+
53
78
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ if File.exists?(File.join(File.expand_path('../..', __FILE__), '.git'))
4
+ diffbench_path = File.expand_path('../../lib', __FILE__)
5
+ $:.unshift(diffbench_path)
6
+ end
7
+
3
8
  require 'diffbench'
4
9
 
5
10
  DiffBench.run(*ARGV)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "diffbench"
8
- s.version = "0.0.2"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = "2012-03-16"
12
+ s.date = "2012-03-23"
13
13
  s.description = "Diffbench is gem designed to benchmark the performance patches. It can run specified benchmark file before and after some changes made and show performance comparation result"
14
14
  s.email = "agresso@gmail.com"
15
15
  s.executables = ["diffbench"]
@@ -33,6 +33,8 @@ Gem::Specification.new do |s|
33
33
  "features/support/env.rb",
34
34
  "lib/diff_bench.rb",
35
35
  "lib/diffbench.rb",
36
+ "spec/bench.rb",
37
+ "spec/code.rb",
36
38
  "spec/diffbench_spec.rb",
37
39
  "spec/spec_helper.rb"
38
40
  ]
@@ -60,7 +60,10 @@ class DiffBench
60
60
  end
61
61
 
62
62
  def run_file
63
- output = `ruby #{@file}`
63
+ output = `ruby -I#{File.dirname(__FILE__)} #{@file}`
64
+ if $?.to_i > 0
65
+ raise Error, "Error exit code: #{$?.to_i}"
66
+ end
64
67
  begin
65
68
  result = YAML.load(output)
66
69
  raise Error, "Can not parse result of ruby script: \n #{output}" unless result.is_a?(Hash)
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift "./lib"
2
+ require 'diffbench'
3
+ load File.dirname(__FILE__) + "/code.rb"
4
+
5
+ DiffBench.bm do
6
+ report "Sleeper 1" do
7
+ Sleeper.run
8
+ end
9
+ report "Sleeper 2" do
10
+ Sleeper.run
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ class Sleeper
2
+
3
+ TIME = 0.2
4
+
5
+ def self.run
6
+ sleep(TIME)
7
+ end
8
+ end
@@ -1,7 +1,46 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
+ require "fileutils"
2
3
 
3
- describe "Diffbench" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
4
+ describe DiffBench do
5
+ let(:repo) do
6
+ "#{File.dirname(__FILE__)}/repo"
6
7
  end
8
+ let!(:git) do
9
+ FileUtils.rm_rf(repo)
10
+ FileUtils.mkdir(repo)
11
+ git = Git.init(repo)
12
+ FileUtils.cp("spec/code.rb", repo)
13
+ git.add("code.rb")
14
+ git.commit("Init")
15
+ git
16
+ end
17
+
18
+
19
+ describe "when git tree is dirty" do
20
+ before do
21
+ content = File.read("#{repo}/code.rb")
22
+ File.open("#{repo}/code.rb", "w") do |f|
23
+ f.write(content.gsub(/TIME = 0\.2/, "TIME = 0.1"))
24
+ end
25
+ FileUtils.cp("spec/bench.rb", "#{repo}/bench.rb")
26
+ end
27
+
28
+ it "should run benchmark with dirty tree and clean tree" do
29
+ puts `cd #{repo}; ./../../bin/diffbench bench.rb`
30
+ end
31
+
32
+ describe "when changes got commit" do
33
+
34
+ before(:each) do
35
+ git.add("code.rb")
36
+ git.commit("Commit")
37
+ end
38
+
39
+ it "should run benchmark with HEAD and HEAD^" do
40
+ puts `cd #{repo}; ./../../bin/diffbench bench.rb`
41
+ end
42
+ end
43
+ end
44
+
45
+
7
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diffbench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-16 00:00:00.000000000 Z
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git
16
- requirement: &16059340 !ruby/object:Gem::Requirement
16
+ requirement: &15252040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16059340
24
+ version_requirements: *15252040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &16058500 !ruby/object:Gem::Requirement
27
+ requirement: &15251480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *16058500
35
+ version_requirements: *15251480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &16057740 !ruby/object:Gem::Requirement
38
+ requirement: &15250800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16057740
46
+ version_requirements: *15250800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cucumber
49
- requirement: &16056880 !ruby/object:Gem::Requirement
49
+ requirement: &15250180 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *16056880
57
+ version_requirements: *15250180
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &16072220 !ruby/object:Gem::Requirement
60
+ requirement: &15249420 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.1.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *16072220
68
+ version_requirements: *15249420
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &16071080 !ruby/object:Gem::Requirement
71
+ requirement: &15248740 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.8.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *16071080
79
+ version_requirements: *15248740
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rcov
82
- requirement: &16070060 !ruby/object:Gem::Requirement
82
+ requirement: &15248240 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *16070060
90
+ version_requirements: *15248240
91
91
  description: Diffbench is gem designed to benchmark the performance patches. It can
92
92
  run specified benchmark file before and after some changes made and show performance
93
93
  comparation result
@@ -114,6 +114,8 @@ files:
114
114
  - features/support/env.rb
115
115
  - lib/diff_bench.rb
116
116
  - lib/diffbench.rb
117
+ - spec/bench.rb
118
+ - spec/code.rb
117
119
  - spec/diffbench_spec.rb
118
120
  - spec/spec_helper.rb
119
121
  homepage: http://github.com/bogdan/diffbench
@@ -131,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
133
  version: '0'
132
134
  segments:
133
135
  - 0
134
- hash: 446831729209371677
136
+ hash: -1898630107307179820
135
137
  required_rubygems_version: !ruby/object:Gem::Requirement
136
138
  none: false
137
139
  requirements: