Skip to content

Multiple inputs & results #12

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Files and directories created by pub
.dart_tool/
.packages

# Conventional directory for build outputs
build/

# Directory created by dartdoc
doc/api/
1 change: 1 addition & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A simple example showcase of memoize library
40 changes: 40 additions & 0 deletions example/bin/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'dart:math' as math;

import 'package:memoize/memoize.dart';

num heavyCalc(num number) {
num sum = 0;
for (int x = 0; x < 999999; x++) {
sum += math.sqrt(number);
}
return sum;
}

void main(List<String> arguments) {
const loops = 99;
print('Some heavy calculations done $loops times with 6 different inputs:');
List<double> numbers = [10000, 4206969, 777, 21372137, 99999999, 10000];
var sumNormal = 0.0;
var w = Stopwatch()..start();
for (int x = 0; x < loops; x++) {
for (var n in numbers) {
sumNormal += heavyCalc(n);
}
}
print('\tNo cache: ${w.elapsedMilliseconds}ms');

var sumCache = 0.0;
w.reset();
var cacheSqrt = memo1(heavyCalc);
for (int x = 0; x < loops; x++) {
for (var n in numbers) {
sumCache += cacheSqrt(n);
}
}
print('\tWith cache: ${w.elapsedMilliseconds}ms');
if (sumNormal == sumCache) {
print("...and results match!");
} else {
print("...but results don't match... guess we broke something :D");
}
}
9 changes: 9 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: example
description: Example showcase of memoize library

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
memoize:
path: ../
Loading