Sha256: 2441aa6e0d706185d18940d1bb3f2f899d84dd981f962f4027533e899410d45f
Contents?: true
Size: 1.06 KB
Versions: 16
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true require "rubygems" require "benchmark" require "ruby-prof" require_relative "cache_runner" RUNS = 1000 RubyProf.measure_mode = RubyProf::CPU_TIME EXTERNALS = { "Memcache" => ["MemCache#set", "MemCache#get"], "Database" => ["Mysql2::Client#query"], } def run(obj) obj.prepare RubyProf.start obj.run result = RubyProf.stop puts "Results for #{obj.class.name}:" results = StringIO.new printer = RubyProf::FlatPrinter.new(result) printer.print(results) count_externals(results.string) end def count_externals(results) count = {} results.split(/\n/).each do |line| fields = line.split if (ext = EXTERNALS.detect { |e| e[1].any? { |method| method == fields[-1] } }) count[ext[0]] ||= 0 count[ext[0]] += fields[-2].to_i end end EXTERNALS.each do |ext| puts "#{ext[0]}: #{count[ext[0]] || 0}" end end create_database(RUNS) run(FindRunner.new(RUNS)) run(FetchHitRunner.new(RUNS)) run(FetchMissRunner.new(RUNS)) run(DoubleFetchHitRunner.new(RUNS)) run(DoubleFetchMissRunner.new(RUNS))
Version data entries
16 entries across 16 versions & 1 rubygems