Last active
January 24, 2019 18:37
-
-
Save hansonw/f7b7f4b32011ee09916dc27a45a43845 to your computer and use it in GitHub Desktop.
Benchmark of rxjs debounceTime vs lodash debounce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: