Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cruby_bench.rb
- ```ruby
- require 'benchmark'
- require 'mysql2'
- Benchmark.bm do |x|
- x.report do
- 100.times do
- client = Mysql2::Client.new(host: 'localhost', username: 'isucon', password: 'isucon', database: 'isuconp')
- client.query('SELECT * FROM comments LIMIT 10').each do |item|
- item['id']
- item['post_id']
- end
- client.close
- end
- end
- end
- ```
- ```ruby
- require 'jdbc/mysql'
- require 'benchmark'
- Jdbc::MySQL.load_driver
- Benchmark.bm do |x|
- x.report do
- 100.times do
- Java::com.mysql.jdbc.Driver
- uri = 'jdbc:mysql://localhost/isuconp'
- connection = java.sql.DriverManager.get_connection(uri, "isucon", "isucon")
- statement = connection.create_statement
- result = statement.execute_query('SELECT * FROM comments LIMIT 10')
- while result.next
- result.getObject('id')
- result.getObject('post_id')
- end
- statement.close
- connection.close
- end
- end
- end
- ```
- ```
- $ ruby -v
- ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
- $ ruby ruby_bench.rb
- user system total real
- 0.020000 0.010000 0.030000 ( 0.054094)
- ```
- ```
- $ jruby -v
- 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]
- $ jruby jruby_bench.rb
- user system total real
- 1.170000 0.010000 1.180000 ( 0.767505)
- ```
- ```
- $ jruby -Xcompile.invokedynamic=true -v
- 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]
- $ jruby -Xcompile.invokedynamic=true jruby_bench.rb
- user system total real
- 1.250000 0.040000 1.290000 ( 0.900037)
- ```
- jruby is slower. with invokedynamic, it rather became more slower.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement