Skip to content

Instantly share code, notes, and snippets.

@ashleighbasil
Created February 24, 2021 17:14
Show Gist options
  • Save ashleighbasil/c896b50ee793c3005bbe93e8d9fd87d8 to your computer and use it in GitHub Desktop.
Save ashleighbasil/c896b50ee793c3005bbe93e8d9fd87d8 to your computer and use it in GitHub Desktop.
Prove aziz wrong on Twitter about comprehension speed
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
@ashleighbasil
Copy link
Author

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

@aziz0x00
Copy link

aziz0x00 commented Mar 1, 2021

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