Skip to content

Instantly share code, notes, and snippets.

@flores
Forked from evanphx/gist:1198447
Created September 6, 2011 18:18
Show Gist options
  • Select an option

  • Save flores/1198501 to your computer and use it in GitHub Desktop.

Select an option

Save flores/1198501 to your computer and use it in GitHub Desktop.

Revisions

  1. @evanphx evanphx created this gist Sep 6, 2011.
    31 changes: 31 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    require 'socket'

    profile = false

    if ARGV.first == "-p"
    profile = true
    ARGV.shift
    end

    port = ARGV.shift
    count = ARGV.shift

    all = count.to_i.times.map do
    s = TCPSocket.new "0.0.0.0", port.to_i
    start = Time.now
    s << "GET /perf/index HTTP/1.0\r\n"
    s << "Host: 0.0.0.0:3001\r\n"
    s << "X-Profile: true\r\n" if profile
    s << "User-Agent: ApacheBench/2.3\r\n"
    s << "Accept: */*\r\n\r\n"
    s.read

    Time.now.to_f - start.to_f
    end

    sum = all.inject { |a,i| a + i}

    mean = sum / count.to_i.to_f

    puts "mean: #{mean}"
    puts "r/s: #{1.0 / mean}"