Skip to content

Instantly share code, notes, and snippets.

@hristo-vrigazov
Created December 30, 2020 10:37
Show Gist options
  • Save hristo-vrigazov/c3b7ae2f04b952f67f84bd2fd390b842 to your computer and use it in GitHub Desktop.
Save hristo-vrigazov/c3b7ae2f04b952f67f84bd2fd390b842 to your computer and use it in GitHub Desktop.
Python example compare
import numpy as np
from time import time
num_experiments = 20
totals = np.zeros(num_experiments)
for i in range(num_experiments):
start = time()
arr = np.random.randint(0, 1000, size=100000000, dtype=np.int32)
print('Generation took ', time() - start)
start = time()
res = arr[(arr > 0) & (arr < 100) | (arr == 170)].sum()
totals[i] = res
print('Processing array took ', time() - start)
@hristo-vrigazov
Copy link
Author

('Generation took ', 0.3448638916015625)
('Processing array took ', 0.37227797508239746)
('Generation took ', 0.3807849884033203)
('Processing array took ', 0.38538098335266113)
('Generation took ', 0.36175012588500977)
('Processing array took ', 0.3823361396789551)
('Generation took ', 0.35578203201293945)
('Processing array took ', 0.38182783126831055)
('Generation took ', 0.3689279556274414)
('Processing array took ', 0.39701390266418457)
('Generation took ', 0.3336331844329834)
('Processing array took ', 0.35786008834838867)
('Generation took ', 0.31902313232421875)
('Processing array took ', 0.3554561138153076)
('Generation took ', 0.31475210189819336)
('Processing array took ', 0.3534219264984131)
('Generation took ', 0.32028698921203613)
('Processing array took ', 0.3608250617980957)
('Generation took ', 0.3139619827270508)
('Processing array took ', 0.36579108238220215)
('Generation took ', 0.32953906059265137)
('Processing array took ', 0.36936092376708984)
('Generation took ', 0.3291499614715576)
('Processing array took ', 0.3569319248199463)
('Generation took ', 0.3185741901397705)
('Processing array took ', 0.3599519729614258)
('Generation took ', 0.3286268711090088)
('Processing array took ', 0.367110013961792)
('Generation took ', 0.3338890075683594)
('Processing array took ', 0.36524200439453125)
('Generation took ', 0.32527709007263184)
('Processing array took ', 0.36179399490356445)
('Generation took ', 0.32627320289611816)
('Processing array took ', 0.36681294441223145)
('Generation took ', 0.32972002029418945)
('Processing array took ', 0.355618953704834)
('Generation took ', 0.317119836807251)
('Processing array took ', 0.36040782928466797)
('Generation took ', 0.3208599090576172)
('Processing array took ', 0.36345791816711426)

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