Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 130 lines (95 sloc) 2.835 kb
28f28c5 @schacon added some simple write ops : add, remove, commit
schacon authored
1 require 'fileutils'
2 require 'benchmark'
3 require 'rubygems'
4 require 'ruby-prof'
5 require 'memcache'
6 require 'pp'
7
8
9 #require 'grit'
10 require 'lib/grit'
11
12 def main
13 @wbare = File.expand_path(File.join('test', 'dot_git'))
14
15 in_temp_dir do
16 #result = RubyProf.profile do
17
18 git = Grit::Repo.new('.')
19 puts Grit::VERSION
20
21 Grit::GitRuby.use_commit_db = true
22 #Grit::GitRuby.cache_client = MemCache.new 'localhost:11211', :namespace => 'grit'
23 #Grit.debug = true
24
25 #pp Grit::GitRuby.cache_client.stats
26
27 commit1 = '5e3ee1198672257164ce3fe31dea3e40848e68d5'
28 commit2 = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
29
30 Benchmark.bm(8) do |x|
31
32 run_code(x, 'packobj') do
33 @commit = git.commit('5e3ee1198672257164ce3fe31dea3e40848e68d5')
34 @tree = git.tree('cd7422af5a2e0fff3e94d6fb1a8fff03b2841881')
35 @blob = git.blob('4232d073306f01cf0b895864e5a5cfad7dd76fce')
36 @commit.parents[0].parents[0].parents[0]
37 end
38
39 run_code(x, 'commits 1') do
40 git.commits.size
41 end
42
43 run_code(x, 'commits 2') do
44 log = git.commits('master', 15)
45 log.size
46 log.size
47 log.first
48 git.commits('testing').map { |c| c.message }
49 end
50
51 run_code(x, 'big revlist') do
52 c = git.commits('master', 200)
53 end
54
55 run_code(x, 'log') do
56 log = git.log('master')
57 log.size
58 log.size
59 log.first
60 end
61
62 run_code(x, 'diff') do
63 c = git.diff(commit1, commit2)
64 end
65
66 run_code(x, 'commit-diff') do
67 c = git.commit_diff(commit1)
68 end
69
70 run_code(x, 'heads') do
71 c = git.heads.collect { |b| b.commit.id }
72 end
73
74 # run_code(x, 'config', 100) do
75 # c = git.config['user.name']
76 # c = git.config['user.email']
77 # end
78
79 #run_code(x, 'commit count') do
80 # c = git.commit_count('testing')
81 #end
82
83
84 end
85 #end
86
87 #printer = RubyProf::FlatPrinter.new(result)
88 #printer.print(STDOUT, 0)
89
90 end
91
92
93 end
94
95
96 def run_code(x, name, times = 30)
97 x.report(name.ljust(12)) do
98 for i in 1..times do
99 yield i
100 end
101 end
102
103 #end
104
105 # Print a graph profile to text
106 end
107
108 def new_file(name, contents)
109 File.open(name, 'w') do |f|
110 f.puts contents
111 end
112 end
113
114
115 def in_temp_dir(remove_after = true)
116 filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
117 tmp_path = File.join("/tmp/", filename)
118 FileUtils.mkdir(tmp_path)
119 Dir.chdir tmp_path do
120 FileUtils.cp_r(@wbare, File.join(tmp_path, '.git'))
121 yield tmp_path
122 end
123 puts tmp_path
124 #FileUtils.rm_r(tmp_path) if remove_after
125 end
126
127 main()
128
129 ##pp Grit::GitRuby.cache_client.stats
Something went wrong with that request. Please try again.