Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Testing pure postgresql adapter perfomance. MacBook Pro i5 4GB
- require 'rubygems'
- gem 'pg','=0.9'
- require 'pg'
- require 'benchmark'
- require 'yaml'
- $db_config = YAML.load(<<DB_CONF)
- adapter: postgresql
- port: 5432
- host: 127.0.0.1
- database: development_1
- username:
- password:
- DB_CONF
- params = [$db_config["host"],$db_config["port"],nil,nil,$db_config["database"],$db_config["username"],$db_config["password"]]
- @connection = PGconn.connect(*params)
- $start_id = 100000
- def bench(i)
- @connection.exec("INSERT INTO USERS (user_id) VALUES (#{$start_id+i});");
- end
- times = []
- @connection.exec("delete from users");
- total_bench = Benchmark.measure do
- 10000.times do |i|
- times << Benchmark.realtime do
- bench(i)
- end
- end
- end
- puts "Total time: #{total_bench.to_s}"
- puts "Average time: #{times.inject(0) {|sum, el| sum+=el }/times.size}"
- # RESULTS
- =begin
- ruby 1.8.7:
- CPUPROFILE=/tmp/rubinius_pg_pure RUBYOPT="-r`gem which perftools | tail -1`" ruby rubinius_pg_pure.rb
- Total time: 0.310000 0.300000 0.610000 ( 12.075894)
- Average time: 0.00119924213886261
- PROFILE: interrupts/evictions/bytes = 73/0/1496
- pprof.rb --text /tmp/rubinius_pg_pure
- Total: 73 samples
- 55 75.3% 75.3% 55 75.3% Object#bench
- 4 5.5% 80.8% 4 5.5% garbage_collector
- 2 2.7% 83.6% 5 6.8% Gem::SourceIndex.load_specification
- 2 2.7% 86.3% 2 2.7% Gem::Version.correct?
- 2 2.7% 89.0% 2 2.7% Kernel#gem_original_require
- 2 2.7% 91.8% 9 12.3% Object#require
- 1 1.4% 93.2% 56 76.7% Benchmark.realtime
- 1 1.4% 94.5% 1 1.4% Gem::GemPathSearcher#matching_files
- 1 1.4% 95.9% 6 8.2% Gem::SourceIndex#load_gems_in
- 1 1.4% 97.3% 3 4.1% Gem::Version#initialize
- 1 1.4% 98.6% 57 78.1% Integer#times
- 1 1.4% 100.0% 1 1.4% Object#Rational
- 0 0.0% 100.0% 1 1.4% Array#map
- 0 0.0% 100.0% 6 8.2% Array#reverse_each
- 0 0.0% 100.0% 1 1.4% Array#select
- 0 0.0% 100.0% 57 78.1% Benchmark.measure
- 0 0.0% 100.0% 7 9.6% Class#new
- 0 0.0% 100.0% 1 1.4% Gem.dir
- 0 0.0% 100.0% 1 1.4% Gem.ensure_gem_subdirectories
- 0 0.0% 100.0% 5 6.8% Gem.find_files
- 0 0.0% 100.0% 1 1.4% Gem.path
- 0 0.0% 100.0% 5 6.8% Gem.searcher
- 0 0.0% 100.0% 1 1.4% Gem.set_home
- 0 0.0% 100.0% 1 1.4% Gem.set_paths
- 0 0.0% 100.0% 6 8.2% Gem.source_index
- 0 0.0% 100.0% 1 1.4% Gem::GemPathSearcher#find_all
- 0 0.0% 100.0% 6 8.2% Gem::GemPathSearcher#init_gemspecs
- 0 0.0% 100.0% 6 8.2% Gem::GemPathSearcher#initialize
- 0 0.0% 100.0% 1 1.4% Gem::GemPathSearcher#matching_file?
- 0 0.0% 100.0% 1 1.4% Gem::Requirement#initialize
- 0 0.0% 100.0% 1 1.4% Gem::Requirement#parse
- 0 0.0% 100.0% 1 1.4% Gem::Requirement.create
- 0 0.0% 100.0% 1 1.4% Gem::Requirement.default
- 0 0.0% 100.0% 5 6.8% Gem::SourceIndex#refresh!
- 0 0.0% 100.0% 5 6.8% Gem::SourceIndex.from_gems_in
- 0 0.0% 100.0% 6 8.2% Gem::SourceIndex.from_installed_gems
- 0 0.0% 100.0% 1 1.4% Gem::SourceIndex.installed_spec_directories
- 0 0.0% 100.0% 3 4.1% Gem::Specification#initialize
- 0 0.0% 100.0% 1 1.4% Gem::Specification#required_rubygems_version=
- 0 0.0% 100.0% 1 1.4% Gem::Specification#version=
- 0 0.0% 100.0% 1 1.4% Gem::Version.create
- 0 0.0% 100.0% 5 6.8% Mutex#synchronize
- rubinius 1.1.0 (1.8.7 release 2010-09-23 JI) [x86_64-apple-darwin10.4.0]:
- rbx -Xprofile rubinius_pg_pure.rb
- Total time: 0.983590 0.326818 1.310408 ( 14.539086)
- Average time: 0.0013994741439819335
- Total running time: 15.055458695s
- % cumulative self self total
- time seconds seconds calls ms/call ms/call name
- ------------------------------------------------------------
- 91.11 13.72 13.72 10001 1.37 1.37 PGconn#exec
- 0.67 14.54 0.10 10001 0.01 1.45 Benchmark.measure
- 0.49 13.79 0.07 10000 0.01 1.38 Object#bench
- 0.47 0.07 0.07 18 3.94 3.94 GC.collect_young
- 0.44 0.07 0.07 20002 0.00 0.00 Process.cpu_times
- 0.30 0.11 0.05 20006 0.00 0.01 Kernel#Float
- 0.30 0.22 0.05 20002 0.00 0.01 Process.times
- 0.29 0.19 0.04 20002 0.00 0.01 Numeric#math_coerce
- 0.28 0.29 0.04 20002 0.00 0.01 Time#to_f
- 0.28 0.06 0.04 36656 0.00 0.00 Type.coerce_to
- 0.26 0.04 0.04 35 1.13 1.13 Rubinius::CodeLoader#load_compiled_file
- 0.22 0.06 0.03 70 0.47 0.81 Rubinius::Melbourne#string_to_ast
- 0.19 0.22 0.03 20002 0.00 0.01 Numeric#redo_coerced
- 0.19 0.14 0.03 20002 0.00 0.01 Float#coerce
- 0.17 0.04 0.03 20002 0.00 0.00 Struct.allocate
- 0.17 0.10 0.03 20496 0.00 0.01 Class#new
- 0.16 0.10 0.02 20002 0.00 0.01 Struct::Tms.new
- 0.14 0.02 0.02 10001 0.00 0.00 Benchmark::Tms#initialize
- 0.13 14.50 0.02 10000 0.00 1.45 Benchmark.realtime
- 0.13 14.53 0.02 10000 0.00 1.45 <anonymous>::__script__<34> {}
- 0.10 0.02 0.02 1574 0.01 0.01 Rubinius::VM.reset_method_cache
- 0.10 0.02 0.02 32839 0.00 0.00 Array#<<
- 0.10 0.01 0.01 20002 0.00 0.00 Struct::Tms#initialize
- 0.09 0.23 0.01 20002 0.00 0.01 Fixnum#divide
- 0.08 0.23 0.01 20002 0.00 0.01 Benchmark.times
- 0.08 0.01 0.01 10253 0.00 0.00 Rubinius::GlobalVariables#[]
- 0.08 14.54 0.01 3 3.88 4846.27 Integer#times
- 0.07 0.01 0.01 56864 0.00 0.00 Type.obj_kind_of?
- 0.07 0.01 0.01 10599 0.00 0.00 Fixnum#to_s
- 0.07 0.34 0.01 3923 0.00 0.09 Array#each
- 0.07 0.01 0.01 40343 0.00 0.00 Kernel#kind_of?
- 0.06 0.01 0.01 5168 0.00 0.00 String#[]
- 0.05 0.01 0.01 2041 0.00 0.00 FFI::Platform::POSIX.stat
- 0.05 13.80 0.01 10000 0.00 1.38 <anonymous>::__script__<35> {}
- 0.05 0.01 0.01 8348 0.00 0.00 Kernel#instance_of?
- 0.05 0.03 0.01 48598 0.00 0.00 Class#allocate
- 0.05 0.01 0.01 40802 0.00 0.00 Kernel#is_a?
- 0.04 0.01 0.01 5313 0.00 0.00 Hash#find_entry
- 0.04 0.02 0.01 3647 0.00 0.01 Hash#[]=
- 0.04 0.01 0.01 11492 0.00 0.00 Hash::Entry#match?
- 0.04 0.01 0.01 20003 0.00 0.00 Time.now
- 0.04 0.00 0.01 50005 0.00 0.00 Float#-
- 0.04 0.01 0.01 4002 0.00 0.00 Regexp#search_region
- 0.04 0.04 0.01 197 0.03 0.21 String#split
- 0.03 0.01 0.01 10000 0.00 0.00 <anonymous>::__script__<42> {}
- 1,377 methods omitted
- 1,422 methods called a total of 1,637,760 times
- rbx -Xprofile rubinius_pg_pure.rb 1,82s user 0,41s system 14% cpu 15,545 total
- == WITHOUT PROFILING
- ruby 1.8.7:
- ruby rubinius_pg_pure.rb
- Total time: 0.310000 0.280000 0.590000 ( 11.489035)
- Average time: 0.0011399943113327
- rubinius:
- rbx rubinius_pg_pure.rb
- Total time: 1.576815 0.328074 1.904889 ( 11.711075)
- Average time: 0.0011454450607299804
- rbx rubinius_pg_pure.rb 2,75s user 0,42s system 25% cpu 12,642 total
- =end
Add Comment
Please, Sign In to add comment