Skip to content

Instantly share code, notes, and snippets.

@hansonw
Last active January 24, 2019 18:37
Show Gist options
  • Select an option

  • Save hansonw/f7b7f4b32011ee09916dc27a45a43845 to your computer and use it in GitHub Desktop.

Select an option

Save hansonw/f7b7f4b32011ee09916dc27a45a43845 to your computer and use it in GitHub Desktop.
Benchmark of rxjs debounceTime vs lodash debounce
const debounce = require('lodash/debounce');
const {Observable} = require('rxjs');
let next;
const observable = Observable.create(observer => {
next = observer.next.bind(observer);
});
let counter = 0;
for (let i = 0; i < 10; i++) {
console.log(`iteration ${i}`);
const subscription = observable.debounceTime(10).subscribe(() => counter++);
let t = Date.now();
for (let j = 0; j < 500000; j++) {
next();
}
console.log('debounceTime:', Date.now() - t);
subscription.unsubscribe();
const debounced = debounce(() => next(), 10);
const subscription2 = observable.subscribe(() => counter++);
t = Date.now();
for (let j = 0; j < 500000; j++) {
debounced();
}
console.log('lodash.debounce:', Date.now() - t);
subscription2.unsubscribe();
}
@hansonw
Copy link
Copy Markdown
Author

hansonw commented Oct 18, 2017

Output:

iteration 0
debounceTime: 1969
lodash.debounce: 121
iteration 1
debounceTime: 593
lodash.debounce: 65
iteration 2
debounceTime: 582
lodash.debounce: 72
iteration 3
debounceTime: 503
lodash.debounce: 61
iteration 4
debounceTime: 414
lodash.debounce: 70
iteration 5
debounceTime: 550
lodash.debounce: 79
iteration 6
debounceTime: 605
lodash.debounce: 86
iteration 7
debounceTime: 524
lodash.debounce: 61
iteration 8
debounceTime: 475
lodash.debounce: 105
iteration 9
debounceTime: 587
lodash.debounce: 87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment