Skip to content

Instantly share code, notes, and snippets.

@thegedge
Created November 23, 2016 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegedge/a468091c002d5f65ea018c2ab28b0da9 to your computer and use it in GitHub Desktop.
Save thegedge/a468091c002d5f65ea018c2ab28b0da9 to your computer and use it in GitHub Desktop.
Run a series of curl requests and profile the mean / std. dev. of those requests
#!/bin/bash
profile-curl() {
local num_iters=500
local num_warmups=10
local -a times
for x in $(seq 1 "${num_warmups}"); do
curl -s -o /dev/null "$@" 2>&1
done
for x in $(seq 1 "${num_iters}"); do
times+=($(curl -s -w '%{time_total}\n' -o /dev/null "$@"))
done
ruby -- - "${times[@]}" <<-EOS
values = ARGV.map(&:to_f)
μ = values.reduce(:+) / values.length
σ = (values.map{ |x| (x - μ)**2 }.reduce(:+) / values.length) ** 0.5
puts "μ = %.4f, σ = %.4f" % [μ, σ]
EOS
}
profile-curl "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment