Skip to Content
Navigation:

A stick figure smiling

If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript".
read the transcript!

programs can be slow for a lot of reasons

Illustration of two programs, each represented by a box with a smiley face.

program 1: I’m waiting for a database query, you?
program 2: I’m using SO MUCH CPU!

it’s not obvious when a program is using CPU

Illustration of a stick figure with curly hair, looking unhappy.

person: my webserver took 6 seconds to respond to that request! why?

panel 3

person: how can I tell how much CPU time was used in this part of my code?

clock-gettime

clock-gettime is a system call. It can tell you how much CPU time your process/thread used since it started.

how to track CPU time

  1. run clock-gettime
  2. do the thing (eg handle a HTTP request)
  3. run clock-gettime
  4. subtract!

this trick works when You have 1 HTTP request per thread at a time

Illustration of Ruby and node.js, each represented by a box with a smiley face.

Ruby: I can use clock-gettime
node.js: doesn’t work for me, I have an event loop!