Skip to content

Commit

Permalink
3.6 has no time_ns
Browse files Browse the repository at this point in the history
  • Loading branch information
byteface committed Jul 10, 2021
1 parent 5f6e383 commit d2db95a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions domonic/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,15 +1893,23 @@ def error(error):

_timers = {}

@staticmethod
def _getTime():
import time
try:
return time.time_ns() // 1000
except Exception:
# python 3.6 doesn't have _ns
return time.time() * 1000000

@staticmethod
def time(label: str):
"""[starts a timer]
Args:
label (str): [The name to give the new timer.]
"""
import time
Console._timers[label] = time.time_ns() // 1000
Console._timers[label] = Console._getTime() # time.time_ns() // 1000

@staticmethod
def timeLog(label: str = None):
Expand All @@ -1915,8 +1923,7 @@ def timeLog(label: str = None):
"""
try:
# if label = None
import time
end = time.time_ns() // 1000
end = Console._getTime() # time.time_ns() // 1000
print(str(end - Console._timers[label]) + "ms")
return str(end - Console._timers[label]) + "ms"
except Exception:
Expand All @@ -1933,8 +1940,7 @@ def timeEnd(label: str):
[type]: [label: time - timer ended]
"""
try:
import time
end = time.time_ns() // 1000
end = Console._getTime() # time.time_ns() // 1000
fin = end - Console._timers[label]
del Console._timers[label]
print(str(label) + ": " + str(fin) + "ms - timer ended")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_x3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_domonic_x3dom(self):
)
)

render( str(x3dom_test), "sphere_test.html" )
render( str(x3dom_test) )#, "sphere_test.html" )


if __name__ == '__main__':
Expand Down

0 comments on commit d2db95a

Please sign in to comment.