Skip to content

Instantly share code, notes, and snippets.

@stokito
Created September 15, 2021 14:19
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 stokito/6f543dc25579aef7bbd583be2c5fb2cf to your computer and use it in GitHub Desktop.
Save stokito/6f543dc25579aef7bbd583be2c5fb2cf to your computer and use it in GitHub Desktop.
Measure request time with curl
time curl -X POST --location "http://127.0.0.1:8080/url" \
  -H "Content-Type: application/json" \
  -d "{\"id\":\"1234567893\"}" \
  -s -o /dev/null -w "%{time_starttransfer}\n"

Output will be like:

127618

real	0m0.139s
user	0m0.001s
sys	0m0.011s

I.e. the real request response time (without DNS lookup) is 127618ns i.e. 0.127618s. The pure curl execution time was 139ms and 1ms curl worked itself and 11ms.

Now we can write a script that will call a hundred times and output request time:

#!/bin/sh
i=0
while [ $i -lt 100 ]; do
  curl -X POST --location "http://127.0.0.1:8080/token1" \
    -H "Content-Type: application/json" \
    -d "{\"id\":\"1234567893\"}" \
    -s -o /dev/null -w "%{time_starttransfer}\n";
  i=$(expr $i + 1)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment