Guest User

Untitled

a guest
Jun 20th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.89 KB | None | 0 0
  1. # Testing pure postgresql adapter perfomance. MacBook Pro i5 4GB
  2.  
  3. require 'rubygems'
  4. gem 'pg','=0.9'
  5. require 'pg'
  6. require 'benchmark'
  7. require 'yaml'
  8.  
  9. $db_config = YAML.load(<<DB_CONF)
  10. adapter: postgresql
  11. port: 5432
  12. host: 127.0.0.1
  13. database: development_1
  14. username:
  15. password:
  16. DB_CONF
  17.  
  18. params = [$db_config["host"],$db_config["port"],nil,nil,$db_config["database"],$db_config["username"],$db_config["password"]]
  19.  
  20.  
  21. @connection = PGconn.connect(*params)
  22.  
  23. $start_id = 100000
  24.  
  25. def bench(i)
  26. @connection.exec("INSERT INTO USERS (user_id) VALUES (#{$start_id+i});");
  27. end
  28.  
  29. times = []
  30.  
  31. @connection.exec("delete from users");
  32.  
  33. total_bench = Benchmark.measure do
  34. 10000.times do |i|
  35. times << Benchmark.realtime do
  36. bench(i)
  37. end
  38. end
  39. end
  40.  
  41. puts "Total time: #{total_bench.to_s}"
  42. puts "Average time: #{times.inject(0) {|sum, el| sum+=el }/times.size}"
  43.  
  44. # RESULTS
  45.  
  46. =begin
  47.  
  48. ruby 1.8.7:
  49.  
  50. CPUPROFILE=/tmp/rubinius_pg_pure RUBYOPT="-r`gem which perftools | tail -1`" ruby rubinius_pg_pure.rb
  51. Total time: 0.310000 0.300000 0.610000 ( 12.075894)
  52. Average time: 0.00119924213886261
  53. PROFILE: interrupts/evictions/bytes = 73/0/1496
  54.  
  55. pprof.rb --text /tmp/rubinius_pg_pure
  56. Total: 73 samples
  57. 55 75.3% 75.3% 55 75.3% Object#bench
  58. 4 5.5% 80.8% 4 5.5% garbage_collector
  59. 2 2.7% 83.6% 5 6.8% Gem::SourceIndex.load_specification
  60. 2 2.7% 86.3% 2 2.7% Gem::Version.correct?
  61. 2 2.7% 89.0% 2 2.7% Kernel#gem_original_require
  62. 2 2.7% 91.8% 9 12.3% Object#require
  63. 1 1.4% 93.2% 56 76.7% Benchmark.realtime
  64. 1 1.4% 94.5% 1 1.4% Gem::GemPathSearcher#matching_files
  65. 1 1.4% 95.9% 6 8.2% Gem::SourceIndex#load_gems_in
  66. 1 1.4% 97.3% 3 4.1% Gem::Version#initialize
  67. 1 1.4% 98.6% 57 78.1% Integer#times
  68. 1 1.4% 100.0% 1 1.4% Object#Rational
  69. 0 0.0% 100.0% 1 1.4% Array#map
  70. 0 0.0% 100.0% 6 8.2% Array#reverse_each
  71. 0 0.0% 100.0% 1 1.4% Array#select
  72. 0 0.0% 100.0% 57 78.1% Benchmark.measure
  73. 0 0.0% 100.0% 7 9.6% Class#new
  74. 0 0.0% 100.0% 1 1.4% Gem.dir
  75. 0 0.0% 100.0% 1 1.4% Gem.ensure_gem_subdirectories
  76. 0 0.0% 100.0% 5 6.8% Gem.find_files
  77. 0 0.0% 100.0% 1 1.4% Gem.path
  78. 0 0.0% 100.0% 5 6.8% Gem.searcher
  79. 0 0.0% 100.0% 1 1.4% Gem.set_home
  80. 0 0.0% 100.0% 1 1.4% Gem.set_paths
  81. 0 0.0% 100.0% 6 8.2% Gem.source_index
  82. 0 0.0% 100.0% 1 1.4% Gem::GemPathSearcher#find_all
  83. 0 0.0% 100.0% 6 8.2% Gem::GemPathSearcher#init_gemspecs
  84. 0 0.0% 100.0% 6 8.2% Gem::GemPathSearcher#initialize
  85. 0 0.0% 100.0% 1 1.4% Gem::GemPathSearcher#matching_file?
  86. 0 0.0% 100.0% 1 1.4% Gem::Requirement#initialize
  87. 0 0.0% 100.0% 1 1.4% Gem::Requirement#parse
  88. 0 0.0% 100.0% 1 1.4% Gem::Requirement.create
  89. 0 0.0% 100.0% 1 1.4% Gem::Requirement.default
  90. 0 0.0% 100.0% 5 6.8% Gem::SourceIndex#refresh!
  91. 0 0.0% 100.0% 5 6.8% Gem::SourceIndex.from_gems_in
  92. 0 0.0% 100.0% 6 8.2% Gem::SourceIndex.from_installed_gems
  93. 0 0.0% 100.0% 1 1.4% Gem::SourceIndex.installed_spec_directories
  94. 0 0.0% 100.0% 3 4.1% Gem::Specification#initialize
  95. 0 0.0% 100.0% 1 1.4% Gem::Specification#required_rubygems_version=
  96. 0 0.0% 100.0% 1 1.4% Gem::Specification#version=
  97. 0 0.0% 100.0% 1 1.4% Gem::Version.create
  98. 0 0.0% 100.0% 5 6.8% Mutex#synchronize
  99.  
  100.  
  101.  
  102.  
  103. rubinius 1.1.0 (1.8.7 release 2010-09-23 JI) [x86_64-apple-darwin10.4.0]:
  104.  
  105. rbx -Xprofile rubinius_pg_pure.rb
  106. Total time: 0.983590 0.326818 1.310408 ( 14.539086)
  107. Average time: 0.0013994741439819335
  108. Total running time: 15.055458695s
  109.  
  110. % cumulative self self total
  111. time seconds seconds calls ms/call ms/call name
  112. ------------------------------------------------------------
  113. 91.11 13.72 13.72 10001 1.37 1.37 PGconn#exec
  114. 0.67 14.54 0.10 10001 0.01 1.45 Benchmark.measure
  115. 0.49 13.79 0.07 10000 0.01 1.38 Object#bench
  116. 0.47 0.07 0.07 18 3.94 3.94 GC.collect_young
  117. 0.44 0.07 0.07 20002 0.00 0.00 Process.cpu_times
  118. 0.30 0.11 0.05 20006 0.00 0.01 Kernel#Float
  119. 0.30 0.22 0.05 20002 0.00 0.01 Process.times
  120. 0.29 0.19 0.04 20002 0.00 0.01 Numeric#math_coerce
  121. 0.28 0.29 0.04 20002 0.00 0.01 Time#to_f
  122. 0.28 0.06 0.04 36656 0.00 0.00 Type.coerce_to
  123. 0.26 0.04 0.04 35 1.13 1.13 Rubinius::CodeLoader#load_compiled_file
  124. 0.22 0.06 0.03 70 0.47 0.81 Rubinius::Melbourne#string_to_ast
  125. 0.19 0.22 0.03 20002 0.00 0.01 Numeric#redo_coerced
  126. 0.19 0.14 0.03 20002 0.00 0.01 Float#coerce
  127. 0.17 0.04 0.03 20002 0.00 0.00 Struct.allocate
  128. 0.17 0.10 0.03 20496 0.00 0.01 Class#new
  129. 0.16 0.10 0.02 20002 0.00 0.01 Struct::Tms.new
  130. 0.14 0.02 0.02 10001 0.00 0.00 Benchmark::Tms#initialize
  131. 0.13 14.50 0.02 10000 0.00 1.45 Benchmark.realtime
  132. 0.13 14.53 0.02 10000 0.00 1.45 <anonymous>::__script__<34> {}
  133. 0.10 0.02 0.02 1574 0.01 0.01 Rubinius::VM.reset_method_cache
  134. 0.10 0.02 0.02 32839 0.00 0.00 Array#<<
  135. 0.10 0.01 0.01 20002 0.00 0.00 Struct::Tms#initialize
  136. 0.09 0.23 0.01 20002 0.00 0.01 Fixnum#divide
  137. 0.08 0.23 0.01 20002 0.00 0.01 Benchmark.times
  138. 0.08 0.01 0.01 10253 0.00 0.00 Rubinius::GlobalVariables#[]
  139. 0.08 14.54 0.01 3 3.88 4846.27 Integer#times
  140. 0.07 0.01 0.01 56864 0.00 0.00 Type.obj_kind_of?
  141. 0.07 0.01 0.01 10599 0.00 0.00 Fixnum#to_s
  142. 0.07 0.34 0.01 3923 0.00 0.09 Array#each
  143. 0.07 0.01 0.01 40343 0.00 0.00 Kernel#kind_of?
  144. 0.06 0.01 0.01 5168 0.00 0.00 String#[]
  145. 0.05 0.01 0.01 2041 0.00 0.00 FFI::Platform::POSIX.stat
  146. 0.05 13.80 0.01 10000 0.00 1.38 <anonymous>::__script__<35> {}
  147. 0.05 0.01 0.01 8348 0.00 0.00 Kernel#instance_of?
  148. 0.05 0.03 0.01 48598 0.00 0.00 Class#allocate
  149. 0.05 0.01 0.01 40802 0.00 0.00 Kernel#is_a?
  150. 0.04 0.01 0.01 5313 0.00 0.00 Hash#find_entry
  151. 0.04 0.02 0.01 3647 0.00 0.01 Hash#[]=
  152. 0.04 0.01 0.01 11492 0.00 0.00 Hash::Entry#match?
  153. 0.04 0.01 0.01 20003 0.00 0.00 Time.now
  154. 0.04 0.00 0.01 50005 0.00 0.00 Float#-
  155. 0.04 0.01 0.01 4002 0.00 0.00 Regexp#search_region
  156. 0.04 0.04 0.01 197 0.03 0.21 String#split
  157. 0.03 0.01 0.01 10000 0.00 0.00 <anonymous>::__script__<42> {}
  158.  
  159. 1,377 methods omitted
  160.  
  161. 1,422 methods called a total of 1,637,760 times
  162. rbx -Xprofile rubinius_pg_pure.rb 1,82s user 0,41s system 14% cpu 15,545 total
  163.  
  164. == WITHOUT PROFILING
  165.  
  166. ruby 1.8.7:
  167.  
  168. ruby rubinius_pg_pure.rb
  169. Total time: 0.310000 0.280000 0.590000 ( 11.489035)
  170. Average time: 0.0011399943113327
  171.  
  172. rubinius:
  173.  
  174. rbx rubinius_pg_pure.rb
  175. Total time: 1.576815 0.328074 1.904889 ( 11.711075)
  176. Average time: 0.0011454450607299804
  177. rbx rubinius_pg_pure.rb 2,75s user 0,42s system 25% cpu 12,642 total
  178.  
  179.  
  180. =end
Add Comment
Please, Sign In to add comment