Author: Brian Kearns <[email protected]>
Branch:
Changeset: r62006:91b8e2795113
Date: 2013-03-04 06:01 -0500
http://bitbucket.org/pypy/pypy/changeset/91b8e2795113/
Log: speed up datetime creation from timestamp significantly
diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py
--- a/lib_pypy/datetime.py
+++ b/lib_pypy/datetime.py
@@ -19,6 +19,9 @@
import time as _time
import math as _math
+def _round(x):
+ return _math.floor(x + 0.5) if x >= 0.0 else _math.ceil(x - 0.5)
+
MINYEAR = 1
MAXYEAR = 9999
@@ -1517,7 +1520,7 @@
converter = _time.localtime if tz is None else _time.gmtime
t, frac = divmod(t, 1.0)
- us = int(round(frac * 1e6))
+ us = int(_round(frac * 1e6))
# If timestamp is less than one microsecond smaller than a
# full second, us can be rounded up to 1000000. In this case,
@@ -1537,7 +1540,7 @@
def utcfromtimestamp(cls, t):
"Construct a UTC datetime from a POSIX timestamp (like time.time())."
t, frac = divmod(t, 1.0)
- us = int(round(frac * 1e6))
+ us = int(_round(frac * 1e6))
# If timestamp is less than one microsecond smaller than a
# full second, us can be rounded up to 1000000. In this case,
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit