srawlins/timezone

How to make TZDateTime faster?

thumbert opened this issue · 0 comments

Hi,

Here's the output for the program below on my machine (Dart 3.0.5):
With UTC DateTime: 20 ms
With local DateTime: 26 ms
With TZDateTime: 61 ms

Both my local tz and the TZDateTime are in the same America/New_York time zone. Can you think of a way to reduce the performance gap between DateTime and TZDateTime? For reference, the equivalent Rust code for TZDateTime runs in 16 ms. That indicates that the Dart's local DateTime is <2x (OK, acceptable), but the TZDateTime 5x is on the slow side.

Thank you for making & maintaining this package. It is absolutely a must.

Tony

main() {
  initializeTimeZones();
  var location = getLocation('America/New_York');
  const H1 = const Duration(hours: 1);
  var sw = Stopwatch()..start();
  var dt = DateTime.utc(2000);
  for (var i = 0; i < 201624; i++) {
    dt = dt.add(H1);
  }
  sw.stop();
  print('With UTC DateTime: ${sw.elapsedMilliseconds} ms');

  sw.start();
  dt = DateTime(2000);
  for (var i = 0; i < 201624; i++) {
    dt = dt.add(H1);
  }
  sw.stop();
  print('With local DateTime: ${sw.elapsedMilliseconds} ms');

  sw.start();
  dt = TZDateTime(location, 2000);
  for (var i = 0; i < 201624; i++) {
    dt = dt.add(H1);
  }
  sw.stop();
  print('With TZDateTime: ${sw.elapsedMilliseconds} ms');
}