File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 5353from .bcast import *
5454from .index import *
5555from .interop import *
56+ from .timer import *
5657
5758# do not export default modules as part of arrayfire
5859del ct
Original file line number Diff line number Diff line change 1+ #######################################################
2+ # Copyright (c) 2015, ArrayFire
3+ # All rights reserved.
4+ #
5+ # This file is distributed under 3-clause BSD license.
6+ # The complete license agreement can be obtained at:
7+ # http://arrayfire.com/licenses/BSD-3-Clause
8+ ########################################################
9+ """
10+ Functions to time arrayfire functions
11+ """
12+
13+ from .library import *
14+ from .device import (sync , eval )
15+ from time import time
16+
17+ def timeit (af_func , * args , min_iters = 10 ):
18+ """
19+ Function to time arrayfire functions.
20+
21+ Parameters
22+ ----------
23+
24+ af_func : arrayfire function
25+
26+ *args : arguments to `af_func`
27+
28+ min_iters : Minimum number of iterations to be run for `af_func`
29+
30+ Returns
31+ --------
32+
33+ t : Time in seconds
34+ """
35+
36+ res = af_func (* args )
37+ eval (res )
38+ sync ()
39+
40+ start = time ()
41+ elapsed = 0
42+ num_iters = 0
43+ while elapsed < 1 :
44+ for n in range (min_iters ):
45+ res = af_func (* args )
46+ eval (res )
47+ sync ()
48+ elapsed += time () - start
49+ num_iters += min_iters
50+
51+ return elapsed / num_iters
You can’t perform that action at this time.
0 commit comments