mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 13:32:36 +08:00
94f32db5e6
* number * gym doesn't have versioning * Benchmarks * visualization * formatting * small fix for tensorboard * first pass removing universe dependency * code * results polish * removed extra line * removed universe dependency * doc * remove gym versioning stuff * changes as suggested * nit
30 lines
715 B
Python
30 lines
715 B
Python
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
|
|
import numpy as np
|
|
from datetime import datetime
|
|
import cProfile, pstats, io
|
|
|
|
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())
|