pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Advertising: Credit Card Consolidation - Cheap Car Insurance - Loans - Loans
Ruby paste-bin - collaborative debugging tool View Help

Posted by Anonymous on Wed 9th Apr 13:16 (modification of post by view diff)
download | new post

  1. #! /usr/bin/env ruby
  2.  
  3. %w{rubygems sequel benchmark}.each { |lib| require lib }
  4.  
  5. def open_db(file)
  6.   @db = Sequel.sqlite(file)
  7. end
  8.  
  9. def create_schema
  10.   @db << "DROP TABLE IF EXISTS SameData;"
  11.   @db << "CREATE TABLE SameData (id INTEGER PRIMARY KEY, foo TEXT, bar TEXT, fnord TEXT);"
  12.   @test_data = @db[:SameData]
  13. end
  14.  
  15. def insert_rows(low, high)
  16.   1000.times do
  17.     @test_data << {:foo => low, :bar => low.reverse, :fnord => high}
  18.   end
  19. end
  20.  
  21. def benchmark
  22.   Benchmark.bm do |bm|
  23.     bm.report { insert_rows("aaaaa", "zzzzz") }
  24.   end 
  25. end
  26.  
  27. if __FILE__ == $0
  28.   open_db('test.db')
  29.   create_schema
  30.   benchmark
  31.   puts "inserted rows: #{@test_data.count}"
  32. end
  33.  
  34. # test 1: "aaa" -> "zzz"
  35. #       user     system      total        real
  36. #   9.200000  14.780000  23.980000 (138.954070)
  37. # inserted rows: 17576
  38. # time/rows = 0,007906
  39.  
  40. # test 2: "00000" -> "99999"
  41. #       user     system      total        real
  42. #  64.090000  76.530000 140.620000 (752.249075)
  43. # inserted rows: 100000
  44. # time/rows = 0,007522
  45.  
  46. # 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.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me
: