forked from rougier/from-python-to-numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.py
More file actions
33 lines (24 loc) · 1.07 KB
/
benchmark.py
File metadata and controls
33 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -----------------------------------------------------------------------------
# From Numpy to Python
# Copyright (2017) Nicolas P. Rougier - BSD license
# More information at https://github.com/rougier/numpy-book
# -----------------------------------------------------------------------------
import numpy as np
from tools import timeit
Z = np.ones(4*1000000, np.float32)
print(">>> Z.view(np.float16)[...] = 0")
timeit("Z.view(np.float16)[...] = 0", globals())
print(">>> Z.view(np.int16)[...] = 0")
timeit("Z.view(np.int16)[...] = 0", globals())
print(">>> Z.view(np.int32)[...] = 0")
timeit("Z.view(np.int32)[...] = 0", globals())
print(">>> Z.view(np.float32)[...] = 0")
timeit("Z.view(np.float32)[...] = 0", globals())
print(">>> Z.view(np.int64)[...] = 0")
timeit("Z.view(np.int64)[...] = 0", globals())
print(">>> Z.view(np.float64)[...] = 0")
timeit("Z.view(np.float64)[...] = 0", globals())
print(">>> Z.view(np.complex128)[...] = 0")
timeit("Z.view(np.complex128)[...] = 0", globals())
print(">>> Z.view(np.int8)[...] = 0")
timeit("Z.view(np.int8)[...] = 0", globals())