karmi (owner)

Revisions

gist: 225110 Download_button fork
public
Public Clone URL: git://gist.github.com/225110.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require 'benchmark'
require 'net/http'
require 'uri'
 
# Usage:
# $ ruby couch_simple_benchmark.rb 100_000
 
uri = URI.parse('http://127.0.0.1:5984')
http = Net::HTTP.start(uri.host, uri.port)
 
num = ARGV.empty? ? 100 : ARGV[0].to_i
 
puts "Putting #{num} simple docs into CouchDB [started at #{Time.now.strftime('%H:%M')}]"
 
Benchmark.bm do |x|
  x.report do
    num.times do |n|
      response = http.post("/fruit", '{"foo":"bar"}')
      raise Exception, "#{response.class} #{response.code}" unless response.code == "201"
    end
  end
end