[python-arrayfire] 166/250: FEAT: Adding timeit function
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:45 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.
commit 68c766d3144af1e662bfc15c4d2b2ef5be701557
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Wed Dec 9 17:45:25 2015 -0500
FEAT: Adding timeit function
---
arrayfire/__init__.py | 1 +
arrayfire/timer.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/arrayfire/__init__.py b/arrayfire/__init__.py
index 1c65fb7..20b5a8a 100644
--- a/arrayfire/__init__.py
+++ b/arrayfire/__init__.py
@@ -53,6 +53,7 @@ from .graphics import *
from .bcast import *
from .index import *
from .interop import *
+from .timer import *
# do not export default modules as part of arrayfire
del ct
diff --git a/arrayfire/timer.py b/arrayfire/timer.py
new file mode 100644
index 0000000..ff33407
--- /dev/null
+++ b/arrayfire/timer.py
@@ -0,0 +1,51 @@
+#######################################################
+# Copyright (c) 2015, ArrayFire
+# All rights reserved.
+#
+# This file is distributed under 3-clause BSD license.
+# The complete license agreement can be obtained at:
+# http://arrayfire.com/licenses/BSD-3-Clause
+########################################################
+"""
+Functions to time arrayfire functions
+"""
+
+from .library import *
+from .device import (sync, eval)
+from time import time
+
+def timeit(af_func, *args, min_iters = 10):
+ """
+ Function to time arrayfire functions.
+
+ Parameters
+ ----------
+
+ af_func : arrayfire function
+
+ *args : arguments to `af_func`
+
+ min_iters : Minimum number of iterations to be run for `af_func`
+
+ Returns
+ --------
+
+ t : Time in seconds
+ """
+
+ res = af_func(*args)
+ eval(res)
+ sync()
+
+ start = time()
+ elapsed = 0
+ num_iters = 0
+ while elapsed < 1:
+ for n in range(min_iters):
+ res = af_func(*args)
+ eval(res)
+ sync()
+ elapsed += time() - start
+ num_iters += min_iters
+
+ return elapsed / num_iters
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git
More information about the debian-science-commits
mailing list