Created
February 24, 2021 17:14
-
-
Save ashleighbasil/c896b50ee793c3005bbe93e8d9fd87d8 to your computer and use it in GitHub Desktop.
Prove aziz wrong on Twitter about comprehension speed
This file contains 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
ash@ly:~$ python3 | |
Python 3.8.5 (default, Jul 28 2020, 12:59:40) | |
[GCC 9.3.0] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from time import perf_counter | |
>>> lst = range(10_000) | |
>>> before = perf_counter(); _=[i for i in lst if i % 2]; perf_counter() - before | |
0.0010968240001147933 | |
## compare to JS | |
ash@ly:~$ node | |
> const arr = [] | |
undefined | |
> for (let i = 0; i < 10000; i++) { arr[i] = i; } | |
9999 | |
> console.time(); arr.filter(e=>e%2); console.timeEnd() | |
default: 1.108ms |
yeah that's my winning card, since js doesnt have inline generator..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
but ur using generators :d :P ok so we could use generators in JS as well and get the same benefit! I'll try it later