Posted by Anonymous on Wed 9th Apr 13:16 (modification of post by view diff)
download | new post
- #! /usr/bin/env ruby
- %w{rubygems sequel benchmark}.each { |lib| require lib }
- def open_db(file)
- @db = Sequel.sqlite(file)
- end
- def create_schema
- @db << "DROP TABLE IF EXISTS SameData;"
- @db << "CREATE TABLE SameData (id INTEGER PRIMARY KEY, foo TEXT, bar TEXT, fnord TEXT);"
- @test_data = @db[:SameData]
- end
- def insert_rows(low, high)
- 1000.times do
- @test_data << {:foo => low, :bar => low.reverse, :fnord => high}
- end
- end
- def benchmark
- Benchmark.bm do |bm|
- bm.report { insert_rows("aaaaa", "zzzzz") }
- end
- end
- if __FILE__ == $0
- open_db('test.db')
- create_schema
- benchmark
- puts "inserted rows: #{@test_data.count}"
- end
- # test 1: "aaa" -> "zzz"
- # user system total real
- # 9.200000 14.780000 23.980000 (138.954070)
- # inserted rows: 17576
- # time/rows = 0,007906
- # test 2: "00000" -> "99999"
- # user system total real
- # 64.090000 76.530000 140.620000 (752.249075)
- # inserted rows: 100000
- # time/rows = 0,007522
- # 133 rows/sec
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.