Skip to content

Is the printer slow? #24

@tcoopman

Description

@tcoopman

I have some code that needs to output a large number of dates to a clean format, but I noticed that this was quite slow.

With this benchmark:

open Core;
open Core_bench.Std;

let main = () => {
	let date = CalendarLib.Calendar.from_unixfloat(1000329.);
  Command.run(
    Bench.make_command([
      Bench.Test.create(~name="format", () => ignore(CalendarLib.Printer.Calendar.sprint("%iT%T%z", date))),
    ]),
  );
};

let () = main();

I get this output:

┌────────┬──────────┬─────────┬──────────┬──────────┬────────────┐
│ Name   │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├────────┼──────────┼─────────┼──────────┼──────────┼────────────┤
│ format │   2.95us │ 721.26w │    1.07w │    1.07w │    100.00% │
└────────┴──────────┴─────────┴──────────┴──────────┴────────────┘

I'm not sure if you are considering this slow, but to me it was totally unexpected that something like this would take up a large amount of time in my code (after benchmarking almost 50% of my time goes to formatting the date).
When using Calendar_Precise it's even a bit slower (about 0,5 microseconds added)

Am I doing something wrong here? Or is this something that is just slow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions