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

How to make TZDateTime faster? #177

Open
thumbert opened this issue Jul 8, 2023 · 0 comments
Open

How to make TZDateTime faster? #177

thumbert opened this issue Jul 8, 2023 · 0 comments

Comments

@thumbert
Copy link

thumbert commented Jul 8, 2023

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');
}
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

1 participant