insect icon indicating copy to clipboard operation
insect copied to clipboard

Show time values in a humanized format?

Open bitzl opened this issue 2 years ago • 1 comments

I'm often using insect to estimate processing times, its such a wonderful tool!

Example: how long would it take to process all 1.3 million items in batches of 100 and an average time 500 ms per batch:

>>> 1.3e6 / 100 * 500 ms -> minutes

  (1300000 / 100) × 500 ms ➞ min

   = 108.333 min

Here it would be super convenient to have a "humanized" version of the output, e.g.

>>> 1.3e6 / 100 * 500 ms -> human

  (1300000 / 100) × 500 ms ➞ human

   = 1h + 48 min + 20 s

Would you be interested to add a feature like this? Would it even be possible?

bitzl avatar Aug 08 '22 09:08 bitzl

Thank you for the feedback. I agree, that would be nice.

At some point, I would like to make the language itself a bit more powerful. That would maybe allow us to implement functionality like this in Insect (the language) itself. Instead of forcing us to implement everything in the interpreter. For example, imagine if we had some formatted printing functionality. Then we could do something like

time = 1.3e6 / 100 * 500 ms -> seconds

num_seconds = time % 60 seconds
num_minutes = (time - num_seconds) % (60 minutes) -> minutes
num_hours = floor((time - num_minutes - num_seconds) / 1 hour) × hour

inside a function, and then print each part.

Somewhat related discussion: https://github.com/sharkdp/insect/issues/263

sharkdp avatar Aug 14 '22 14:08 sharkdp

In the follow-up project, https://numbat.dev/, we can do this:

let time = 17.47 hours

let num_seconds = mod(time -> seconds, 60 seconds)
let num_minutes = mod(time - num_seconds, 60 minutes) -> minutes // floor
let num_hours = floor((time - num_minutes - num_seconds) / 1 hour) × hour -> hours

assert_eq(num_hours + num_minutes + num_seconds -> s, time -> s, 1ms)

print("{num_hours/h}:{num_minutes/min}:{num_seconds/s}")

and it prints 17:28:12.

I have opened https://github.com/sharkdp/numbat/issues/181 as a follow-up ticket.

sharkdp avatar Sep 26 '23 20:09 sharkdp

@bitzl The exact syntax that you proposed is now available in Numbat (the follow up project): https://numbat.dev/?q=1.3e6+%2F+100+*+500+ms+-%3E+human%E2%8F%8E

sharkdp avatar Feb 12 '24 21:02 sharkdp

Thank you, that's great news! I'm already happily using Numbat a lot.

bitzl avatar Feb 12 '24 22:02 bitzl