Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the printer slow? #24

Open
tcoopman opened this issue Jun 12, 2019 · 2 comments
Open

Is the printer slow? #24

tcoopman opened this issue Jun 12, 2019 · 2 comments

Comments

@tcoopman
Copy link

tcoopman commented Jun 12, 2019

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?

@tcoopman
Copy link
Author

I've just done a quick test with ptime Ptime.to_rfc3339(date, ~tz_offset_s=0) and this seems already quite a bit faster.

┌──────────────┬────────────┬─────────┬──────────┬──────────┬────────────┐
│ Name         │   Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├──────────────┼────────────┼─────────┼──────────┼──────────┼────────────┤
│ format       │ 3_017.74ns │ 721.26w │    1.07w │    1.07w │    100.00% │
│ format ptime │   889.41ns │ 215.01w │          │          │     29.47% │
└──────────────┴────────────┴─────────┴──────────┴──────────┴────────────┘

@pmetzger
Copy link
Member

Unfortunately, at the moment, we de facto don't have a maintainer for calendar. This means it is likely that until such a person steps up, you may be on your own on this. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants