Show More
@@ -1084,25 +1084,33 def _format_time(timespan, precision=3): | |||
|
1084 | 1084 | # E.g. eclipse is able to print a µ, but has no sys.stdout.encoding set. |
|
1085 | 1085 | |
|
1086 | 1086 | |
|
1087 |
units = [ |
|
|
1087 | units = [u"s", u"ms",u'us',"ns"] # the save value | |
|
1088 | 1088 | if sys.stdout.encoding: |
|
1089 | 1089 | try: |
|
1090 | 1090 | u'\xb5'.encode(sys.stdout.encoding) |
|
1091 |
units = [ |
|
|
1091 | units = [u"s", u"ms",u'\xb5s',"ns"] | |
|
1092 | 1092 | except: |
|
1093 | 1093 | pass |
|
1094 |
scaling = [ |
|
|
1094 | scaling = [1, 1e3, 1e6, 1e9] | |
|
1095 | 1095 | |
|
1096 |
if timespan > |
|
|
1097 | order = min(-int(math.floor(math.log10(timespan)) // 3), 3)+2 | |
|
1098 | elif timespan >= 3660.0: | |
|
1099 | # hours | |
|
1100 |
|
|
|
1101 | elif timespan >= 60.0: | |
|
1102 | # minutes | |
|
1103 | order = 1 | |
|
1104 | else: | |
|
1105 | order = 5 | |
|
1096 | if timespan >= 60.0: | |
|
1097 | # we have more than a minute, format that in a human readable form | |
|
1098 | # Idea from http://snipplr.com/view/5713/ | |
|
1099 | parts = [("d", 60*60*24),("h", 60*60),("min", 60), ("s", 1)] | |
|
1100 | time = [] | |
|
1101 | leftover = timespan | |
|
1102 | for suffix, length in parts: | |
|
1103 | value = int(leftover / length) | |
|
1104 | if value > 0: | |
|
1105 | leftover = leftover % length | |
|
1106 | time.append(u'%s%s' % (str(value), suffix)) | |
|
1107 | if leftover < 1: | |
|
1108 | break | |
|
1109 | return " ".join(time) | |
|
1106 | 1110 | |
|
1111 | if timespan > 0.0: | |
|
1112 | order = min(-int(math.floor(math.log10(timespan)) // 3), 3) | |
|
1113 | else: | |
|
1114 | order = 3 | |
|
1107 | 1115 | ret = u"%.*g %s" % (precision, timespan * scaling[order], units[order]) |
|
1108 | 1116 | return ret |
General Comments 0
You need to be logged in to leave comments.
Login now