Skip to content

Commit

Permalink
Add timing module Konstantinos needs for some demos.
Browse files Browse the repository at this point in the history
  • Loading branch information
lebedov committed Oct 12, 2015
1 parent c641b1d commit 0c9f5b6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions neurokernel/tools/timing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import time


class Timer(object):
def __init__(self, name=None):
self.name = name

def __enter__(self):
self.tstart = time.time()
if self.name is None:
print('Starting timer'.format(self.name))
else:
print('Starting {}'.format(self.name))

def __exit__(self, type, value, traceback):
if self.name is None:
print('Elapsed time: {0:.2f}s'
.format(time.time() - self.tstart))
else:
print('Elapsed time for {1}: {0:.2f}s'
.format(time.time() - self.tstart, self.name))


def main():
with Timer():
time.sleep(1)
with Timer('Test'):
time.sleep(2)

if __name__ == '__main__':
main()

0 comments on commit 0c9f5b6

Please sign in to comment.