From 397ad2056eb7fe17a42eebf13b0a53a728e4c91c Mon Sep 17 00:00:00 2001 From: neingeist Date: Sat, 19 Sep 2015 18:40:30 +0200 Subject: [PATCH] Test memory_profiler --- mem-profile.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 mem-profile.py diff --git a/mem-profile.py b/mem-profile.py new file mode 100644 index 0000000..db86928 --- /dev/null +++ b/mem-profile.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +from memory_profiler import profile +import numpy as np + +# From +# http://stackoverflow.com/questions/27464039/why-the-performance-difference-between-numpy-zeros-and-numpy-zeros-like + +N = (1000, 1000) +M = (slice(None, 500, None), slice(500, None, None)) + +@profile +def test1(N, M): + print(N, M) + x = np.zeros(N) + y = np.empty(N) + z = np.zeros_like(x) + x[M] = 1 + y[M] = 1 + z[M] = 1 + return x,y,z + +test1(N, M)