[
  {
    "path": ".gitignore",
    "content": "*.log\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: bash\nbefore_install:\n  - sudo apt-get update -qq\n  - sudo apt-get install -qq bats\nscript:\n  - make\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Thanks for helping with ttfb!\n\nTests live in the [`tests/tests.bats` file](tests/tests.bats) if you're adding a bugfix or making a small change, please ensure all tests pass. \n\nTo run the tests, call `make` from the project root. You'll need to have [bats-core](https://github.com/bats-core/bats-core) installed and in your `$PATH`.\n\nIf you only want to run a test or two, uncomment the `# skip` lines on the tests you don't care about, so they read `skip`, and then those tests will be skipped.\n\nIf you're thinking about new functionality, check that it can't be achieved by passing `-o` options to curl; for instance, there's no need to raise a PR that makes `ttfb` ignore invalid certificates, you can achieve this by calling ttfb like `ttfb -o \"-k\" https://example.com` - the `-k` option is added to the `curl` call, and will therefore ignore invalid or expired certificates.\n\nIf you do want to add new functionality, please also add a test to [`tests/tests.bats` file](tests/tests.bats).\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2019 Jay Caines-Gooby\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "Makefile",
    "content": "default: test\n\n.PHONY: check-bats-exists\ncheck-bats-exists:\n\t@which bats > /dev/null || (echo \"Missing dependency. You need to ensure that 'bats' is installed and in your \\$$PATH. See https://github.com/bats-core/bats-core\" && exit 1)\n\n.PHONY: test\ntest: check-bats-exists\n\tbats tests/\n"
  },
  {
    "path": "README.md",
    "content": "# Introduction\n\nMeasures [time-to-first-byte](https://en.wikipedia.org/wiki/Time_to_first_byte) for single or multiple URLs. Can show you quickest, slowest & median TTFB values plus optionally log all response headers.\n\n[![Build Status](https://app.travis-ci.com/jaygooby/ttfb.sh.svg?branch=master)](https://app.travis-ci.com/jaygooby/ttfb.sh)\n\n![Sample run of ttfb.sh](https://github.com/jaygooby/ttfb.sh/raw/readme-assets/demo.gif)\n\n```\nUsage: ttfb [options] url [url...]\n\t-d debug\n\t-l <log file> (infers -d) log response headers. Defaults to ./curl.log\n\t-n <number> of times to test time to first byte\n\t-o <option> pass options to curl (e.g. -o \"-k\" will make curl ignore invalid certificates)\n\t-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)\n```\n\nImplicitly follows a redirection chain using curl's `-L` option.\n\nCan log all response headers (the default log file is `./curl.log`) by calling with `-d`.\n\nOverride the default log file by specifying `-l /some/file`.\n\nGet quickest, slowest and median TTFB values by specifying the number of times to call a URL; use `-n2` for 2 tests, `-n5` for 5 and so on.\n\nUses the calculation `%{time_starttransfer¹} - %{time_appconnect²}` which doesn't include any connection overhead, to better approximate [devtool’s TTFB figure](https://developers.google.com/web/tools/chrome-devtools/network/understanding-resource-timing#slow_time_to_first_byte).\n\n¹ [`time_starttransfer`](https://github.com/curl/curl/blob/e431daf013ea04cb1a988a2009d820224ef5fb79/docs/cmdline-opts/write-out.d#L141-L144)\n> The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.</blockquote>\n\n² [`time_appconnect`](https://github.com/curl/curl/blob/e431daf013ea04cb1a988a2009d820224ef5fb79/docs/cmdline-opts/write-out.d#L118-L120)\n>The time, in seconds, it took from the start until the SSL/SSH/etc\nconnect/handshake to the remote host was completed.\n\n# Genesis\nBased on a [gist](https://gist.github.com/sandeepraju/1f5fbdbdd89551ba7925abe2645f92b5)\nby https://github.com/sandeepraju\n\nModified by jay@gooby.org, [@jaygooby](https://twitter.com/jaygooby)\n\n# Installation\nDownload the script from the master branch and make it executable:\n```\ncurl -LJO https://raw.githubusercontent.com/jaygooby/ttfb.sh/master/ttfb\nchmod +x ./ttfb\n```\n\n# Usage\n\n```\nUsage: ttfb [options] url [url...]\n\t-d debug\n\t-l <log file> (infers -d) log response headers. Defaults to ./curl.log\n\t-n <number> of times to test time to first byte\n\t-o <option> pass options to curl (e.g. -o \"-k\" will make curl ignore invalid certificates)\n\t-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)\n```\n\n## Examples\n\nBasic usage:\n\n```\n$ ttfb example.com\n.227436\n```\n\nBasic usage with verbose response breakdown:\n\n```\n$ ttfb -v https://example.com\nDNS lookup: 0.005152 TLS handshake: 0.000000 TTFB including connection: 0.200831 TTFB: .200831 Total time: 0.201132\n```\n\nTest multiple times:\n\n```\n$ ttfb -n 5 example.com/example/url\n.....\nfastest .177263 slowest .214302 median .179957\n```\n\nTest multiple URLs:\n\n```\n$ ttfb bbc.co.uk news.bbc.co.uk\nbbc.co.uk        .049985\nnews.bbc.co.uk   .054122\n```\n\nTest multiple URLs, multiple times:\n\n```\n$ ttfb -n 5 bbc.co.uk news.bbc.co.uk\n.....\n.....\nbbc.co.uk       fastest .030936 slowest .057755 median .034663\nnews.bbc.co.uk  fastest .031413 slowest .182791 median .035001\n```\n\nVerbose response breakdown when multiple tests specified:\n\n```\n$ ttfb -v -n 5 bbc.co.uk\nDNS lookup: 0.005335 TLS handshake: 0.102314 TTFB including connection: 0.148328 TTFB: .046014 Total time: 0.646115\nDNS lookup: 0.005322 TLS handshake: 0.102609 TTFB including connection: 0.150693 TTFB: .048084 Total time: 0.644611\nDNS lookup: 0.004277 TLS handshake: 0.102066 TTFB including connection: 0.172199 TTFB: .070133 Total time: 1.196256\nDNS lookup: 0.004444 TLS handshake: 0.107375 TTFB including connection: 0.160771 TTFB: .053396 Total time: 0.637290\nDNS lookup: 0.005352 TLS handshake: 0.118882 TTFB including connection: 0.168772 TTFB: .049890 Total time: 0.653761\n\nfastest .046014 slowest .070133 median .049890\n```\n\nLog all the response headers for multiple tests to multiple URLs:\n\n```\nttfb -d -n 2 bbc.co.uk https://www.bbc.co.uk/weather\n..\n..\nbbc.co.uk                      fastest .027550 slowest .055215 median .041382\nhttps://www.bbc.co.uk/weather  fastest .101020 slowest .297923 median .199471\n\n$ ls *.log\nbbc_co_uk-curl.log                     https___www_bbc_co_uk_weather-curl.log\n\n$ cat https___www_bbc_co_uk_weather-curl.log\nHTTP/2 200\nserver: openresty\nx-cache-action: MISS\nvary: Accept-Encoding,X-BBC-Edge-Cache,X-BBC-Edge-Scheme,X-CDN\nx-cache-age: 0\ncache-control: private, stale-while-revalidate=10, max-age=0, must-revalidate\ncontent-type: text/html;charset=utf-8\nx-mrid: w1\ndate: Thu, 11 Apr 2019 17:08:07 GMT\nx-xss-protection: 1; mode=block\nx-content-type-options: nosniff\nx-lb-nocache: true\nx-msig: 24e37f81323984e4e45b8048f9e3c94a\nx-frame-options: SAMEORIGIN\ncontent-length: 1077454\n\nHTTP/2 200\nserver: openresty\nx-cache-action: MISS\nvary: Accept-Encoding,X-BBC-Edge-Cache,X-BBC-Edge-Scheme,X-CDN\nx-cache-age: 0\ncache-control: private, stale-while-revalidate=10, max-age=0, must-revalidate\ncontent-type: text/html;charset=utf-8\nx-mrid: w1\ndate: Thu, 11 Apr 2019 17:08:08 GMT\nx-xss-protection: 1; mode=block\nx-content-type-options: nosniff\nx-lb-nocache: true\nx-msig: 24e37f81323984e4e45b8048f9e3c94a\nx-frame-options: SAMEORIGIN\ncontent-length: 1077454\n```\n\n# More detail on time-to-first-byte\n\nSee https://blog.cloudflare.com/a-question-of-timing/\nand https://curl.haxx.se/docs/manpage.html for an explanation\nof how the curl variables relate to the various stages of\nthe transfer.\n\n![Diagram showing what each of the curl variable timings refer to against a typical HTTP over TLS 1.2 connection](https://blog.cloudflare.com/content/images/2018/10/Screen-Shot-2018-10-16-at-14.51.29-1.png)\n\nTo get a better approximation of devtool's TTFB, we consider\nthe time without the connection overhead:\n`%{time_starttransfer} - %{time_appconnect}`\n\nUses a dirty `eval` to do the ttfb arithmetic. Depends\non `bc` and `column` commands.\n\n# Testing\n\nIf you'd like to submit a [PR](https://github.com/jaygooby/ttfb.sh/pulls), please ensure all existing tests pass and if it adds new functionality, add a test in the [test suite](https://github.com/jaygooby/ttfb.sh/blob/master/tests/tests.bats).\n\nTo run the tests, call `make` from the project root. You'll need to have [bats-core](https://github.com/bats-core/bats-core) installed and in your `$PATH`.\n\nIf you only want to run a test or two, uncomment the `# skip` lines on the tests you don't care about, so they read `skip`, and then those tests will be skipped.\n\nSee [`CONTRIBUTING.md`](CONTRIBUTING.md) for more details.\n\n# TODO\n\n  * [x] Show progress when more than one request (`-n 2` etc) option is set\n\n\t* [x] Allow custom options to be passed to curl (use the `-o` option)\n\n  * [ ] Sort output by fastest TTFB when multiple URLs are supplied\n\n  * [ ] Colour code the `TTFB:` figure in the standard response, according to the speed of the response.\n"
  },
  {
    "path": "tests/tests.bats",
    "content": "#!/usr/bin/env bats\n#\n# To skip a test, just uncomment the # skip line\n\n@test \"-? switch\" {\n  # skip\n  run ./ttfb -?\n  [[ \"$output\" =~ \"Usage: \" ]]\n}\n\n@test \"Invalid switch\" {\n  # skip\n  run ./ttfb -Z\n\n  [ $status -ne 0 ]\n  [[ \"$output\" =~ \"Usage: \" ]]\n}\n\n@test \"-d logs requests to ./curl.log\" {\n  # skip\n  rundir=\"$(mktemp -d)\"\n  pwd=\"$PWD\"\n  cd \"$rundir\" && run \"$pwd/ttfb\" -d example.com\n  [ $status -eq 0 ]\n  [ -f \"$rundir/curl.log\" ]\n}\n\n@test \"-l logs to specific file\" {\n  # skip\n  rundir=\"$(mktemp -d)\"\n  logdir=\"$(mktemp -d)\"\n  pwd=\"$PWD\"\n  cd \"$rundir\" && run \"$pwd/ttfb\" -l \"$logdir/log.log\" example.com\n  [ $status -eq 0 ]\n  [ -f \"$logdir/log.log\" ]\n}\n\n@test \"-l exits if the path the custom log file doesn't exist\" {\n  # skip\n  rundir=\"$(mktemp -d)\"\n  logdir=\"$(mktemp -d)\"\n  rmdir \"$logdir\"\n  pwd=\"$PWD\"\n  cd \"$rundir\" && run \"$pwd/ttfb\" -l \"$logdir/log.log\" example.com\n  [ $status -eq 1 ]\n}\n\n@test \"-n expects an argument\" {\n  # skip\n  run ./ttfb -n example.com\n  [ $status -ne 0 ]\n  [[ \"$output\" =~ \"Usage: \" ]]\n}\n\n@test \"-n runs test multiple times\" {\n  # skip\n  run ./ttfb -n 3 example.com\n  [ $status -eq 0 ]\n  [[ \"$output\" =~ \"...\" ]]\n  [[ \"$output\" =~ \"fastest\" ]]\n}\n\n@test \"can test multiple urls\" {\n  # skip\n  run ./ttfb example.com example.com/hello-world\n  [ $status -eq 0 ]\n  [[ \"$output\" =~ \"example.com\" ]]\n  [[ \"$output\" =~ \"example.com/hello-world\" ]]\n}\n\n@test \"can test multiple urls multiple times\" {\n  # skip\n  run ./ttfb -n 3 example.com example.com/hello-world\n  [ $status -eq 0 ]\n  [[ \"$output\" =~ \"...\" ]]\n  [[ \"$output\" =~ \"example.com\" ]]\n  [[ \"$output\" =~ \"example.com/hello-world\" ]]\n}\n\n@test \"-d logs requests to multiple urls to multiple log files\" {\n  # skip\n  rundir=\"$(mktemp -d)\"\n  pwd=\"$PWD\"\n  cd \"$rundir\" && run \"$pwd/ttfb\" -d example.com example.com/hello-world\n  [ $status -eq 0 ]\n  [ -f \"$rundir/example_com-curl.log\" ]\n  [ -f \"$rundir/example_com_hello_world-curl.log\" ]\n}\n\n@test \"-l logs requests to multiple urls to multiple custom log files\" {\n  # skip\n  rundir=\"$(mktemp -d)\"\n  pwd=\"$PWD\"\n  cd \"$rundir\" && run \"$pwd/ttfb\" -l \"$rundir/custom.log\" example.com example.com/hello-world\n  [ $status -eq 0 ]\n  [ -f \"$rundir/example_com-custom.log\" ]\n  [ -f \"$rundir/example_com_hello_world-custom.log\" ]\n}\n\n@test \"-d logs multiple requests to multiple urls to multiple log files\" {\n  # skip\n  rundir=\"$(mktemp -d)\"\n  pwd=\"$PWD\"\n  cd \"$rundir\" && run \"$pwd/ttfb\" -n2 -d example.com example.com/hello-world\n  [ $status -eq 0 ]\n  [ -f \"$rundir/example_com-curl.log\" ]\n  [ -f \"$rundir/example_com_hello_world-curl.log\" ]\n  [ $(grep \" 200 OK\" \"$rundir/example_com-curl.log\" | wc -l) -eq 2 ]\n  [ $(grep \" 404 Not Found\" \"$rundir/example_com_hello_world-curl.log\" | wc -l) -eq 2 ]\n}\n\n@test \"-d logs multiple requests to multiple urls to multiple custom log files\" {\n  # skip\n  rundir=\"$(mktemp -d)\"\n  pwd=\"$PWD\"\n  cd \"$rundir\" && run \"$pwd/ttfb\" -n2 -l \"$rundir/custom.log\" example.com example.com/hello-world\n  [ $status -eq 0 ]\n  [ -f \"$rundir/example_com-custom.log\" ]\n  [ -f \"$rundir/example_com_hello_world-custom.log\" ]\n  [ $(grep \" 200 OK\" \"$rundir/example_com-custom.log\" | wc -l) -eq 2 ]\n  [ $(grep \" 404 Not Found\" \"$rundir/example_com_hello_world-custom.log\" | wc -l) -eq 2 ]\n}\n\n@test \"pass custom curl options via our -o option\" {\n  # This test passes -k to curl, so it can successfully\n  # call https://self-signed.badssl.com which has a self-signed certificate\n  # which would normally result in a fail\n  # skip\n  run \"$pwd/ttfb\" -o \"-k\" https://self-signed.badssl.com\n  [[ \"$output\" != \"0\" ]]\n}\n"
  },
  {
    "path": "ttfb",
    "content": "#!/usr/bin/env bash\n#\n# Shows time in seconds to first byte of a url or urls\n#\n# Based on a gist https://gist.github.com/sandeepraju/1f5fbdbdd89551ba7925abe2645f92b5\n# by https://github.com/sandeepraju\n#\n# Modified by jay@gooby.org, @jaygooby\n#\n# Usage: ttfb [options] url [url...]\n#   -d debug\n#   -l <log file> (infers -d) log response headers. Defaults to ./curl.log\n#   -n <number> of times to test time to first byte\n#   -o <option> pass options to curl (e.g. -o \"-k\" will make curl ignore invalid certificates)\n#   -v verbose output. Show request breakdown during -n calls\n#\n# Examples:\n#\n# ttfb https://example.com/example/url\n# .098974\n#\n# ttfb -n 5 https://example.com/\n# .....\n# fastest .099195 slowest .103138 median .099684\n#\n# ttfb -n 5 bbc.co.uk news.bbc.co.uk\n# .....\n# .....\n# bbc.co.uk       fastest .045873 slowest .046870 median .045999\n# news.bbc.co.uk  fastest .042286 slowest .060245 median .046035\n#\n# ttfb bbc.co.uk news.bbc.co.uk\n# bbc.co.uk        .048378\n# news.bbc.co.uk   .049303\n#\n# Implicitly follows redirects using curl's -L option.\n#\n# Log all response headers (default log file is ./curl.log) by calling with -d\n#\n# Override the default log file by specifying -l /some/file\n#\n# Get min, max and median values by specifying the number of times to call\n# the URL; use -n2 for 2 tests, -n5 for 5 and so on.\n#\n# If you specify more than one url and have specified -d or -l, the log file\n# will be prefixed with the URL being requested.\n#\n# If you specify -n and -d or -l, the response headers from the consecutive\n# requests will be concatenated in the log file.\n#\n# See https://blog.cloudflare.com/a-question-of-timing/\n# and https://curl.haxx.se/docs/manpage.html for an explanation\n# of how the curl variables relate to the various stages of\n# the transfer.\n#\n# To get a better approximation of devtool's TTFB, consider\n# the time without the connection overhead:\n# %{time_starttransfer} - %{time_appconnect}\n#\n# Uses a dirty eval to do the ttfb arithmetic. Depends\n# on bc and column commands.\nset -eu\n\n# check dependencies\nfor dependency in curl bc column; do\n  which $dependency > /dev/null || (echo \"You need to have '$dependency' installed and in your \\$PATH\" >&2 && exit 1)\ndone\n\n# Ensure curl uses period separators for floating point values, which\n# bc requires to do calculations (i.e. it can't use locale separators like ,)\nif (locale -a | egrep ^C.UTF-8$ > /dev/null); then\n  export LC_ALL=C.UTF-8\nelse\n  export LC_ALL=C\nfi\n\n# check curl can use http2\nHTTP_VERSION=\"--http2\"\ncurl -so /dev/null --http2 https://example.com || HTTP_VERSION=\"--http1.1\"\n\n# Cribbed from https://stackoverflow.com/a/41762669/391826\nmedian() {\n  arr=($(printf '%s\\n' \"${@}\" | sort -n))\n  nel=${#arr[@]}\n  if (( $nel % 2 == 1 )); then     # Odd number of elements\n    val=\"${arr[ $(($nel/2)) ]}\"\n  else                            # Even number of elements\n    (( j=nel/2 ))\n    (( k=j-1 ))\n    val=$(echo \"scale=6;(${arr[j]}\" + \"${arr[k]})\"/2|bc -l)\n  fi\n  echo $val\n}\n\nshow_usage() {\n  echo -e \"Usage: ttfb [options] url [url...]\\n\\t-d debug\\n\\t-l <log file> (infers -d) log response headers. Defaults to ./curl.log\\n\\t-n <number> of times to test time to first byte\\n\\t-o <option> pass options to curl (e.g. -o \\\"-k\\\" will make curl ignore invalid certificates)\\n\\t-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)\" >&2\n}\n\n# defaults\nDEBUG=\"\"\nLOG=\"\"\nNUM_REQUESTS=0\nVERBOSE=0\noptions=()\n\nwhile getopts \"dl:n:o:v\" OPTION\ndo\n    case $OPTION in\n        d) DEBUG=1 ;;\n        l) LOG=\"$OPTARG\" ;;\n        n) NUM_REQUESTS=$OPTARG ;;\n        o) options+=(\"$(echo $OPTARG | xargs)\") ;;\n        v) VERBOSE=1 ;;\n        \\?) show_usage\n            exit 1\n            ;;\n    esac\ndone\n\nshift $((OPTIND - 1))  # shifts away every option argument,\n                       # leaving urls as $@\n\nif [ -z \"${1:-}\" ]; then\n  show_usage\n  exit 1\nelse\n  URLS=\"$@\"\nfi\n\n# if we're given a custom log file, or log directory, implicitly set DEBUG=1\n[ -n \"$LOG\" ] && DEBUG=1\n\n# default the log file to curl.log in pwd or LOG_DIRECTORY if -o was specified\nLOG=\"${LOG:-curl.log}\"\n\n# now work out if $LOG is relative or an absolute path\n# and then get the dirname\n[ \"$LOG\" != \"${LOG#/}\" ] && LOG_DIRECTORY=$(dirname \"$LOG\") || LOG_DIRECTORY=$(dirname \"${PWD}/$LOG\")\nif [ ! -d \"$LOG_DIRECTORY\" ]; then\n   echo \"Log directory $LOG_DIRECTORY doesn't exist\" >&2\n   exit 1;\nfi\n\n# then set the actual log filename\nLOG=$(basename \"$LOG\")\n\nDEBUG=${DEBUG:-0}\n\noptions+=(-o /dev/null)\noptions+=(-s)\noptions+=(-L)\noptions+=($HTTP_VERSION)\noptions+=(-H 'Cache-Control: no-cache')\noptions+=(-w 'echo DNS lookup: %{time_namelookup} TLS handshake: %{time_appconnect} TTFB including connection: %{time_starttransfer} TTFB: $(echo %{time_starttransfer} - %{time_appconnect} | bc) Total time: %{time_total} \\n')\n\nfor URL in $URLS; do\n\n  if [ $DEBUG -eq 1 ]; then\n    if [ ${#@} -gt 1 ]; then\n      LOGFILE=\"${URL//[^[:alnum:]]/_}\"\n      options+=(-D \"${LOG_DIRECTORY}/${LOGFILE}-${LOG}\")\n    else\n      options+=(-D \"${LOG_DIRECTORY}/${LOG}\")\n    fi\n  fi\n  # if we're checking more than one url\n  # output the url on the results line\n  if [ ${#@} -gt 1 ]; then\n    SHOW_URL=\"${URL}|\"\n    if [[ $VERBOSE -eq 1 && -n \"$NUM_REQUESTS\" && \"$NUM_REQUESTS\" -gt 1 ]]; then\n      echo $URL >&2\n    fi\n  else\n    SHOW_URL=\"\"\n  fi\n\n  # if multiple requests have been specified, then show min, max & median values\n  if [[ -n \"$NUM_REQUESTS\" && \"$NUM_REQUESTS\" -gt 1 ]]; then\n    ttfbs=()\n    for i in $(seq $NUM_REQUESTS); do\n\n      # if we're checking more than one url, and debug is set, then log\n      # the headers to a per-url file, but also for each request\n      if [[ ${#@} -gt 1 && $DEBUG -eq 1 ]]; then\n        LOGFILE=\"${URL//[^[:alnum:]]/_}\"\n        options+=(-D \"${LOG_DIRECTORY}/${LOGFILE}-${LOG}_${i}\")\n      elif [ $DEBUG -eq 1 ]; then\n        # we only have the one URL, but we still are requesting multiple\n        # ttfb calls, so log the headers\n        options+=(-D \"${LOG_DIRECTORY}/${LOG}_${i}\")\n      fi\n\n      request=$(eval $(curl \"${options[@]}\" \"$URL\"))\n      ttfbs+=($(echo $request | grep -oE \"TTFB: .{0,7}\" | cut -d' ' -f2 | sort -n));\n      if [ $VERBOSE -eq 1 ]; then\n        echo \"$request\" >&2\n      else\n        printf \".\" >&2\n      fi\n    done\n\n    # tidy up - combine multiple request logs for the same url into a single file\n    if [[ ${#@} -gt 1 && $DEBUG -eq 1 ]]; then\n      cat \"${LOG_DIRECTORY}/${LOGFILE}-${LOG}_\"* > \"${LOG_DIRECTORY}/${LOGFILE}-${LOG}\"\n      rm \"${LOG_DIRECTORY}/${LOGFILE}-${LOG}_\"*\n    elif [ $DEBUG -eq 1 ]; then\n      cat \"${LOG_DIRECTORY}/${LOG}_\"* > \"${LOG_DIRECTORY}/${LOG}\"\n      rm \"${LOG_DIRECTORY}/${LOG}_\"*\n    fi\n\n    printf \"\\n\" >&2\n    # sort the times\n    ttfbs=( $( printf \"%s\\n\" \"${ttfbs[@]}\" | sort -n ) )\n    # show quickest, slowest and median fftb\n    printf \"${SHOW_URL}\\e[32mfastest \\e[39m${ttfbs[0]} \\e[91mslowest \\e[39m${ttfbs[${#ttfbs[*]}-1]} \\e[95mmedian \\e[39m$(median ${ttfbs[*]})\\e[39m\\n\";\n  else\n   if [ $VERBOSE -eq 1 ]; then\n     echo -e $SHOW_URL $(eval $(curl \"${options[@]}\" \"$URL\"))\n   else\n     echo -e $SHOW_URL $(eval $(curl \"${options[@]}\" \"$URL\") | grep -oE \"TTFB: .{0,7}\" | cut -d' ' -f2)\n   fi\n  fi\ndone | column -s'|' -t\n"
  }
]