##// END OF EJS Templates
cleanup
Matthias Bussonnier -
Show More
@@ -1,40 +1,40 b''
1 # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
1 # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2 # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
2 # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3
3
4 name: Python package
4 name: Python package
5
5
6 on:
6 on:
7 push:
7 push:
8 branches: [ master, 7.x ]
8 branches: [ master, 7.x ]
9 pull_request:
9 pull_request:
10 branches: [ master, 7.x ]
10 branches: [ master, 7.x ]
11
11
12 jobs:
12 jobs:
13 build:
13 formatting:
14
14
15 runs-on: ubuntu-latest
15 runs-on: ubuntu-latest
16 timeout-minutes: 10
16 timeout-minutes: 5
17 strategy:
17 strategy:
18 matrix:
18 matrix:
19 python-version: [3.8]
19 python-version: [3.8]
20
20
21 steps:
21 steps:
22 - uses: actions/checkout@v2
22 - uses: actions/checkout@v2
23 with:
23 with:
24 fetch-depth: 0
24 fetch-depth: 0
25 - name: Set up Python ${{ matrix.python-version }}
25 - name: Set up Python ${{ matrix.python-version }}
26 uses: actions/setup-python@v2
26 uses: actions/setup-python@v2
27 with:
27 with:
28 python-version: ${{ matrix.python-version }}
28 python-version: ${{ matrix.python-version }}
29 - name: Install dependencies
29 - name: Install dependencies
30 run: |
30 run: |
31 python -m pip install --upgrade pip
31 python -m pip install --upgrade pip
32 pip install darker isort
32 pip install darker
33 - name: Lint with darker
33 - name: Lint with darker
34 run: |
34 run: |
35 darker -r 60625f241f298b5039cb2debc365db38aa7bb522 --check --diff . || (
35 darker -r 60625f241f298b5039cb2debc365db38aa7bb522 --check --diff . || (
36 echo "Changes need auto-formatting. Run:"
36 echo "Changes need auto-formatting. Run:"
37 echo " darker -r 60625f241f298b5039cb2debc365db38aa7bb522"
37 echo " darker -r 60625f241f298b5039cb2debc365db38aa7bb522"
38 echo "then commit and push changes to fix."
38 echo "then commit and push changes to fix."
39 exit 1
39 exit 1
40 )
40 )
@@ -1,122 +1,123 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 Utilities for timing code execution.
3 Utilities for timing code execution.
4 """
4 """
5
5
6 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
7 # Copyright (C) 2008-2011 The IPython Development Team
7 # Copyright (C) 2008-2011 The IPython Development Team
8 #
8 #
9 # Distributed under the terms of the BSD License. The full license is in
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 import time
17 import time
18
18
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Code
20 # Code
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22
22
23 # If possible (Unix), use the resource module instead of time.clock()
23 # If possible (Unix), use the resource module instead of time.clock()
24 try:
24 try:
25 import resource
25 import resource
26 except ImportError:
26 except ImportError:
27 resource = None
27 resource = None
28
28
29 # Some implementations (like jyputerlite) don't have getrusage
29 # Some implementations (like jyputerlite) don't have getrusage
30 if resource is not None and hasattr(resource, "getrusage"):
30 if resource is not None and hasattr(resource, "getrusage"):
31 def clocku():
31 def clocku():
32 """clocku() -> floating point number
32 """clocku() -> floating point number
33
33
34 Return the *USER* CPU time in seconds since the start of the process.
34 Return the *USER* CPU time in seconds since the start of the process.
35 This is done via a call to resource.getrusage, so it avoids the
35 This is done via a call to resource.getrusage, so it avoids the
36 wraparound problems in time.clock()."""
36 wraparound problems in time.clock()."""
37
37
38 return resource.getrusage(resource.RUSAGE_SELF)[0]
38 return resource.getrusage(resource.RUSAGE_SELF)[0]
39
39
40 def clocks():
40 def clocks():
41 """clocks() -> floating point number
41 """clocks() -> floating point number
42
42
43 Return the *SYSTEM* CPU time in seconds since the start of the process.
43 Return the *SYSTEM* CPU time in seconds since the start of the process.
44 This is done via a call to resource.getrusage, so it avoids the
44 This is done via a call to resource.getrusage, so it avoids the
45 wraparound problems in time.clock()."""
45 wraparound problems in time.clock()."""
46
46
47 return resource.getrusage(resource.RUSAGE_SELF)[1]
47 return resource.getrusage(resource.RUSAGE_SELF)[1]
48
48
49 def clock():
49 def clock():
50 """clock() -> floating point number
50 """clock() -> floating point number
51
51
52 Return the *TOTAL USER+SYSTEM* CPU time in seconds since the start of
52 Return the *TOTAL USER+SYSTEM* CPU time in seconds since the start of
53 the process. This is done via a call to resource.getrusage, so it
53 the process. This is done via a call to resource.getrusage, so it
54 avoids the wraparound problems in time.clock()."""
54 avoids the wraparound problems in time.clock()."""
55
55
56 u,s = resource.getrusage(resource.RUSAGE_SELF)[:2]
56 u,s = resource.getrusage(resource.RUSAGE_SELF)[:2]
57 return u+s
57 return u+s
58
58
59 def clock2():
59 def clock2():
60 """clock2() -> (t_user,t_system)
60 """clock2() -> (t_user,t_system)
61
61
62 Similar to clock(), but return a tuple of user/system times."""
62 Similar to clock(), but return a tuple of user/system times."""
63 return resource.getrusage(resource.RUSAGE_SELF)[:2]
63 return resource.getrusage(resource.RUSAGE_SELF)[:2]
64
64
65 else:
65 else:
66 # There is no distinction of user/system time under windows, so we just use
66 # There is no distinction of user/system time under windows, so we just use
67 # time.perff_counter() for everything...
67 # time.perff_counter() for everything...
68 clocku = clocks = clock = time.perf_counter
68 clocku = clocks = clock = time.perf_counter
69
69 def clock2():
70 def clock2():
70 """Under windows, system CPU time can't be measured.
71 """Under windows, system CPU time can't be measured.
71
72
72 This just returns perf_counter() and zero."""
73 This just returns perf_counter() and zero."""
73 return time.perf_counter(),0.0
74 return time.perf_counter(),0.0
74
75
75
76
76 def timings_out(reps,func,*args,**kw):
77 def timings_out(reps,func,*args,**kw):
77 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
78 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
78
79
79 Execute a function reps times, return a tuple with the elapsed total
80 Execute a function reps times, return a tuple with the elapsed total
80 CPU time in seconds, the time per call and the function's output.
81 CPU time in seconds, the time per call and the function's output.
81
82
82 Under Unix, the return value is the sum of user+system time consumed by
83 Under Unix, the return value is the sum of user+system time consumed by
83 the process, computed via the resource module. This prevents problems
84 the process, computed via the resource module. This prevents problems
84 related to the wraparound effect which the time.clock() function has.
85 related to the wraparound effect which the time.clock() function has.
85
86
86 Under Windows the return value is in wall clock seconds. See the
87 Under Windows the return value is in wall clock seconds. See the
87 documentation for the time module for more details."""
88 documentation for the time module for more details."""
88
89
89 reps = int(reps)
90 reps = int(reps)
90 assert reps >=1, 'reps must be >= 1'
91 assert reps >=1, 'reps must be >= 1'
91 if reps==1:
92 if reps==1:
92 start = clock()
93 start = clock()
93 out = func(*args,**kw)
94 out = func(*args,**kw)
94 tot_time = clock()-start
95 tot_time = clock()-start
95 else:
96 else:
96 rng = range(reps-1) # the last time is executed separately to store output
97 rng = range(reps-1) # the last time is executed separately to store output
97 start = clock()
98 start = clock()
98 for dummy in rng: func(*args,**kw)
99 for dummy in rng: func(*args,**kw)
99 out = func(*args,**kw) # one last time
100 out = func(*args,**kw) # one last time
100 tot_time = clock()-start
101 tot_time = clock()-start
101 av_time = tot_time / reps
102 av_time = tot_time / reps
102 return tot_time,av_time,out
103 return tot_time,av_time,out
103
104
104
105
105 def timings(reps,func,*args,**kw):
106 def timings(reps,func,*args,**kw):
106 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
107 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
107
108
108 Execute a function reps times, return a tuple with the elapsed total CPU
109 Execute a function reps times, return a tuple with the elapsed total CPU
109 time in seconds and the time per call. These are just the first two values
110 time in seconds and the time per call. These are just the first two values
110 in timings_out()."""
111 in timings_out()."""
111
112
112 return timings_out(reps,func,*args,**kw)[0:2]
113 return timings_out(reps,func,*args,**kw)[0:2]
113
114
114
115
115 def timing(func,*args,**kw):
116 def timing(func,*args,**kw):
116 """timing(func,*args,**kw) -> t_total
117 """timing(func,*args,**kw) -> t_total
117
118
118 Execute a function once, return the elapsed total CPU time in
119 Execute a function once, return the elapsed total CPU time in
119 seconds. This is just the first value in timings_out()."""
120 seconds. This is just the first value in timings_out()."""
120
121
121 return timings_out(1,func,*args,**kw)[0]
122 return timings_out(1,func,*args,**kw)[0]
122
123
General Comments 0
You need to be logged in to leave comments. Login now