mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 19:17:01 +08:00
3ebfd850e1
* Test examples for pep8 compliance. * Make rl_pong example pep8 compliant. * Make policy gradient example pep8 compliant. * Make lbfgs example pep8 compliant. * Make hyperopt example pep8 compliant. * Make a3c example pep8 compliant. * Make evolution strategies example pep8 compliant. * Make resnet example pep8 compliant. * Fix.
34 lines
664 B
Python
34 lines
664 B
Python
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
|
|
from datetime import datetime
|
|
import cProfile
|
|
import io
|
|
import pstats
|
|
|
|
|
|
def timestamp():
|
|
return datetime.now().timestamp()
|
|
|
|
|
|
def time_string():
|
|
return datetime.now().strftime("%Y%m%d_%H_%M_%f")
|
|
|
|
|
|
class Profiler(object):
|
|
def __init__(self):
|
|
self.pr = cProfile.Profile()
|
|
pass
|
|
|
|
def __enter__(self):
|
|
self.pr.enable()
|
|
|
|
def __exit__(self, type, value, traceback):
|
|
self.pr.disable()
|
|
s = io.StringIO()
|
|
sortby = "cumtime"
|
|
ps = pstats.Stats(self.pr, stream=s).sort_stats(sortby)
|
|
ps.print_stats(.2)
|
|
print(s.getvalue())
|