darq 0.2.0 copy "darq: ^0.2.0" to clipboard
darq: ^0.2.0 copied to clipboard

outdated

The power of lazy-evaluated enumerables in your hands! (A port of functional LINQ from the .NET library.)

example/main.dart

import 'package:darq/darq.dart';

void main() {
  benchmark();
}

void benchmark() {
  final source = List.generate(1000000, (i) => i);
  final iterations = 100;
  final benchmarks = List<double>(iterations);

  // LINQ style
  for (int i = 0; i < iterations; i++) {
    final start = DateTime.now();

    // ======================BENCHMARK START=============================
    final result =
        E(source).groupByE((i) => i % 3).selectE((g) => g.averageE());
    for (var _ in result) {
      // Do something with the value
    }
    // ======================BENCHMARK END===============================

    final end = DateTime.now();

    benchmarks[i] =
        (end.microsecondsSinceEpoch - start.microsecondsSinceEpoch) / 1000000;
  }

  print(
      'Average execution time in seconds (LINQ): ${E(benchmarks).averageE()}');

  // Vanilla Style
  for (int i = 0; i < iterations; i++) {
    final start = DateTime.now();

    // ======================BENCHMARK START=============================
    final result = <List<int>>[[], [], []];
    for (var i in source) {
      result[i % 3].add(i);
    }
    for (var g in result) {
      var total = 0;
      for (var i in g) {
        total += i;
      }
      final _ = total / g.length;
      // Go something with the value
    }
    // ======================BENCHMARK END===============================

    final end = DateTime.now();

    benchmarks[i] =
        (end.microsecondsSinceEpoch - start.microsecondsSinceEpoch) / 1000000;
  }

  print(
      'Average execution time in seconds (Vanilla): ${E(benchmarks).averageE()}');
}
142
likes
0
pub points
95%
popularity

Publisher

unverified uploader

The power of lazy-evaluated enumerables in your hands! (A port of functional LINQ from the .NET library.)

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on darq