Created
October 2, 2015 23:40
-
-
Save tenderlove/17d1da05c010d9e91f1a to your computer and use it in GitHub Desktop.
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 'benchmark' | |
require 'csv' | |
GEM_REPO = 'many_gems' | |
ENV['GEM_HOME'] = GEM_REPO | |
ENV['GEM_PATH'] = GEM_REPO | |
N = 15 | |
MEDIAN = N / 2 | |
Gem.clear_paths # clear all of rubygems cache | |
times = (100..1000).step(100).map { |i| | |
Dir.chdir(GEM_REPO) { system "git checkout #{i}" } | |
worst_gem = "pkg#{i - 1}" | |
gem_req = N.times.map { | |
start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) | |
Process.waitpid fork { gem worst_gem; require worst_gem; } | |
Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) - start | |
}.sort[MEDIAN] | |
bare_req = N.times.map { | |
start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) | |
Process.waitpid fork { require worst_gem; } | |
Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) - start | |
}.sort[MEDIAN] | |
[i, gem_req, bare_req] | |
} | |
CSV($stdout) do |csv| | |
csv << ['number of gems', 'gem "foo"; require "foo"', 'require "foo"'] | |
times.each { |t| csv << t } | |
end |
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
### | |
# Use this to generate many gems. | |
require 'rubygems/specification' | |
require 'fileutils' | |
require 'thread' | |
def util_spec name, version = 2, deps = nil # :yields: specification | |
spec = Gem::Specification.new do |s| | |
s.platform = Gem::Platform::RUBY | |
s.name = name | |
s.version = version | |
s.author = 'A User' | |
s.email = 'example@example.com' | |
s.homepage = 'http://example.com' | |
s.summary = "this is a summary" | |
s.description = "This is a test description" | |
yield s if block_given? | |
end | |
if deps then | |
# Since Hash#each is unordered in 1.8, sort the keys and iterate that | |
# way so the tests are deterministic on all implementations. | |
deps.keys.sort.each do |n| | |
spec.add_dependency n, (deps[n] || '>= 0') | |
end | |
end | |
spec | |
end | |
queue = Queue.new | |
thread_num = (ENV['P'] || 4).to_i | |
threads = thread_num.times.map { | |
Thread.new do | |
while w = queue.pop | |
x = util_spec("pkg#{w}", 1, {}) { |s| s.files << "lib/pkg#{w}.rb" } | |
Gem::Installer.for_spec(x).install | |
end | |
end | |
} | |
N = (ENV['N'] || 1_000).to_i | |
N.times { |i| queue << i } | |
thread_num.times { |i| queue << nil } | |
threads.each(&:join) | |
Dir.chdir ENV['GEM_HOME'] do | |
system "git add ." | |
system "git commit -am'#{N}'" | |
system "git tag #{N}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment