Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. cruby_bench.rb
  2.  
  3. ```ruby
  4. require 'benchmark'
  5. require 'mysql2'
  6.  
  7. Benchmark.bm do |x|
  8. x.report do
  9. 100.times do
  10. client = Mysql2::Client.new(host: 'localhost', username: 'isucon', password: 'isucon', database: 'isuconp')
  11. client.query('SELECT * FROM comments LIMIT 10').each do |item|
  12. item['id']
  13. item['post_id']
  14. end
  15. client.close
  16. end
  17.  
  18. end
  19. end
  20. ```
  21.  
  22.  
  23. ```ruby
  24. require 'jdbc/mysql'
  25. require 'benchmark'
  26.  
  27. Jdbc::MySQL.load_driver
  28.  
  29. Benchmark.bm do |x|
  30. x.report do
  31. 100.times do
  32.  
  33. Java::com.mysql.jdbc.Driver
  34. uri = 'jdbc:mysql://localhost/isuconp'
  35. connection = java.sql.DriverManager.get_connection(uri, "isucon", "isucon")
  36. statement = connection.create_statement
  37. result = statement.execute_query('SELECT * FROM comments LIMIT 10')
  38.  
  39. while result.next
  40. result.getObject('id')
  41. result.getObject('post_id')
  42. end
  43.  
  44. statement.close
  45. connection.close
  46. end
  47.  
  48. end
  49. end
  50. ```
  51.  
  52.  
  53. ```
  54. $ ruby -v
  55. ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
  56. $ ruby ruby_bench.rb
  57. user system total real
  58. 0.020000 0.010000 0.030000 ( 0.054094)
  59. ```
  60.  
  61. ```
  62. $ jruby -v
  63. jruby 9.1.5.0 (2.3.1) 2016-09-07 036ce39 Java HotSpot(TM) 64-Bit Server VM 24.80-b11 on 1.7.0_80-b15 +jit [linux-x86_64]
  64. $ jruby jruby_bench.rb
  65. user system total real
  66. 1.170000 0.010000 1.180000 ( 0.767505)
  67. ```
  68.  
  69. ```
  70. $ jruby -Xcompile.invokedynamic=true -v
  71. jruby 9.1.5.0 (2.3.1) 2016-09-07 036ce39 Java HotSpot(TM) 64-Bit Server VM 24.80-b11 on 1.7.0_80-b15 +indy +jit [linux-x86_64]
  72. $ jruby -Xcompile.invokedynamic=true jruby_bench.rb
  73. user system total real
  74. 1.250000 0.040000 1.290000 ( 0.900037)
  75. ```
  76.  
  77. jruby is slower. with invokedynamic, it rather became more slower.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement