logger icon indicating copy to clipboard operation
logger copied to clipboard

Higher time resolution for newTimeCache?

Open portnov opened this issue 7 years ago • 3 comments

As far as I can see, the whole TimedFastLogger thing is primarily intended for the case when one wants to print time to log with precision of one second only. But, I have some experience with applications where a thousand events in a millisecond is not an exceptional situation. In such applications, it becomes essential to log time with precision of at least a millisecond.

Questions are

  1. Am I right that newTimeCache creates a "cache" that refreshes not more often than one time in a second?

  2. Do you have any practical insights, if a similar time caching mechanism with update interval of 1 millisecond will give any advantage comparing to directly formatting time each time?

The suggestion is to add new function newTimeCache', which would take one additional argument - update interval.

portnov avatar Nov 15 '17 08:11 portnov

Cc: @winterland1989

kazu-yamamoto avatar Nov 17 '17 07:11 kazu-yamamoto

@portnov

  1. Yes you are right, IIRC newTimeCache use auto-update package to achieve this.

  2. The time cost are:

  • syscall to fetch time, average 1~10 microsecond.
  • the formatting processing which convert time to string, average 10~100 microsecond.

It's quite costly if you update the cache every millisecond. auto-update package use a complicated locking system to avoid unnecessary update(when you don't fetch the cache), but that also add some overhead, especially on multi-ghc-threaded programs.

winterland1989 avatar Nov 17 '17 09:11 winterland1989

Thanks for the information.

portnov avatar Nov 17 '17 15:11 portnov