If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!
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
- run clock-gettime
- do the thing (eg handle a HTTP request)
- run clock-gettime
- 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!
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!