Last active
December 11, 2015 20:49
-
-
Save danielstjules/4658271 to your computer and use it in GitHub Desktop.
svn/git init/commit performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'grit' | |
require 'svn/repos' | |
# Folders to store repos | |
GITREPOS = 'gitrepos' | |
SVNREPOS = 'svnrepos' | |
# Class for creating and commiting to svn repositories | |
class SvnRepo | |
def initialize(repo_name) | |
@path = File.join('svnrepos/', repo_name) | |
Svn::Repos.create(@path, {}) | |
@repo = Svn::Repos.open(@path) | |
end | |
def commit | |
# Create dummy file test.txt and commit it | |
txn = @repo.fs.transaction | |
file = 'text.txt' | |
txn.root.make_file file | |
stream = txn.root.apply_text(file) | |
stream.write('hello world') | |
stream.close | |
@repo.commit(txn) | |
end | |
def close | |
@repo.close | |
end | |
end | |
# Class for creating and commiting to git repositories | |
class GitRepo | |
def initialize(repo_name) | |
@path = File.join('gitrepos/', repo_name) | |
@repo = Grit::Repo.init_bare(@path) | |
end | |
def commit | |
# Create dummy file test.txt and commit it | |
File.open("#{@path}/test.txt", 'w') { |f| f.puts 'hello world' } | |
Dir.chdir("#{@path}") { @repo.add('test.txt') } | |
@repo.commit_index('add file') | |
end | |
end | |
# Create folders to hold repos | |
FileUtils.mkdir SVNREPOS if !File.exists?(SVNREPOS) | |
FileUtils.mkdir GITREPOS if !File.exists?(GITREPOS) | |
# Create 10,000 svn repos | |
beginning_time = Time.now | |
(1..10000).each { |i| SvnRepo.new(i.to_s) } | |
end_time = Time.now | |
puts "Creating 10,000 svn repos: #{(end_time - beginning_time)*1000} ms" | |
# Create 10,000 git repos | |
beginning_time = Time.now | |
(1..10000).each { |i| GitRepo.new(i.to_s) } | |
end_time = Time.now | |
puts "Creating 10,000 git repos: #{(end_time - beginning_time)*1000} ms" | |
# Create and commit test.txt to 10,000 svn repos | |
beginning_time = Time.now | |
(10001..20000).each do |i| | |
repo = SvnRepo.new(i.to_s) | |
repo.commit | |
repo.close | |
end | |
end_time = Time.now | |
puts "Creating and commiting to 10,000 svn repos: #{(end_time - beginning_time)*1000} ms" | |
# Create and commit test.txt to 10,000 git repos | |
beginning_time = Time.now | |
(10001..20000).each do |i| | |
repo = GitRepo.new(i.to_s) | |
repo.commit | |
end | |
end_time = Time.now | |
puts "Creating and commiting to 10,000 git repos: #{(end_time - beginning_time)*1000} ms" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment