massivefermion / birl

datetime handling for gleam
https://hex.pm/packages/birl
Apache License 2.0
72 stars 9 forks source link

What Am I Doing Wrong? #19

Closed codereport closed 6 months ago

codereport commented 6 months ago

I am trying to manually time some functions runtime in Gleam. I am using birl. However, the following timing code doesnt seem to work at all. Am I doing something wrong? (by wrong, I mean that the actually runtime of the code is much longer then the millisecond differences produced by the code below)

import birl
import birl/duration
import gleam/int
import gleam/io
import gleam/list

pub fn main() {

  let times = [birl.utc_now()]
  // do something
  let times = times |> list.append([birl.utc_now()])
  // do something
  let times = times |> list.append([birl.utc_now()])
  // do something
  let times = times |> list.append([birl.utc_now()])

  // print timing results
  list.each(list.zip(list.drop(times, 1), times), fn(pair) {
    let #(a, b) = pair
    let duration.Duration(micro) = birl.difference(a, b)
    let milli = micro / 1000
    io.print(",")
    io.print(milli |> int.to_string)
  })
}
codereport commented 6 months ago

Library works perfect. I shouldn't have been converting to milliseconds.