Skip to content

Commit e9fc56d

Browse files
authored
Add time.monotonic (#947)
1 parent f9ff8e0 commit e9fc56d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

Src/IronPython.Modules/time.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
using System.Diagnostics;
99
using System.Globalization;
1010
using System.Linq;
11+
using System.Numerics;
1112
using System.Runtime.CompilerServices;
1213
using System.Text;
1314
using System.Threading;
1415

15-
using Microsoft.Scripting;
16-
using Microsoft.Scripting.Runtime;
17-
using Microsoft.Scripting.Utils;
18-
1916
using IronPython.Runtime;
2017
using IronPython.Runtime.Operations;
2118
using IronPython.Runtime.Types;
2219

20+
using Microsoft.Scripting;
21+
using Microsoft.Scripting.Runtime;
22+
2323
[assembly: PythonModule("time", typeof(IronPython.Modules.PythonTime))]
2424
namespace IronPython.Modules {
2525
public static class PythonTime {
@@ -127,6 +127,13 @@ public static void sleep(double tm) {
127127
Thread.Sleep((int)(tm * 1000));
128128
}
129129

130+
public static double monotonic()
131+
=> (double)Stopwatch.GetTimestamp() / Stopwatch.Frequency;
132+
133+
// new in Python 3.7
134+
public static BigInteger monotonic_ns()
135+
=> (BigInteger)Stopwatch.GetTimestamp() * 1000000000 / Stopwatch.Frequency;
136+
130137
public static double time() {
131138
return TicksToTimestamp(DateTime.Now.ToUniversalTime().Ticks);
132139
}

0 commit comments

Comments
 (0)