|
17 | 17 | using System.Threading; |
18 | 18 |
|
19 | 19 | using IronPython.Runtime; |
| 20 | +using IronPython.Runtime.Exceptions; |
20 | 21 | using IronPython.Runtime.Operations; |
21 | 22 | using IronPython.Runtime.Types; |
22 | 23 |
|
@@ -106,18 +107,31 @@ public static double clock() { |
106 | 107 |
|
107 | 108 | public static double perf_counter() => clock(); |
108 | 109 |
|
| 110 | + public static double process_time() => Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds; |
| 111 | + |
109 | 112 | public static string ctime(CodeContext/*!*/ context) |
110 | 113 | => asctime(context, localtime()); |
111 | 114 |
|
112 | 115 | public static string ctime(CodeContext/*!*/ context, object? seconds) |
113 | 116 | => asctime(context, localtime(seconds)); |
114 | 117 |
|
115 | | - public static object get_clock_info([NotNone] string name) { |
| 118 | + public static object get_clock_info(CodeContext/*!*/ context, [NotNone] string name) { |
116 | 119 | // TODO: Fill with correct values |
117 | | - if (name == "monotonic") |
118 | | - return new SimpleNamespace(new Dictionary<string, object?> { { "adjustable", false }, { "implementation", "Stopwatch.GetTimestamp" }, { "monotonic", true }, { "resolution", 0.015625 } }); |
119 | | - |
120 | | - throw new NotImplementedException(); |
| 120 | + switch (name) { |
| 121 | + case "monotonic": |
| 122 | + return new SimpleNamespace(new Dictionary<string, object?> { { "adjustable", false }, { "implementation", "Stopwatch.GetTimestamp" }, { "monotonic", true }, { "resolution", 0.015625 } }); |
| 123 | + case "perf_counter": |
| 124 | + return new SimpleNamespace(new Dictionary<string, object?> { { "adjustable", false }, { "implementation", "Stopwatch.ElapsedTicks" }, { "monotonic", true }, { "resolution", 1e-7 } }); |
| 125 | + case "process_time": |
| 126 | + return new SimpleNamespace(new Dictionary<string, object?> { { "adjustable", false }, { "implementation", "Process.TotalProcessorTime" }, { "monotonic", true }, { "resolution", 1e-7 } }); |
| 127 | + case "clock": |
| 128 | + PythonOps.Warn(context, PythonExceptions.DeprecationWarning, "time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead"); |
| 129 | + return new SimpleNamespace(new Dictionary<string, object?> { { "adjustable", false }, { "implementation", "Stopwatch.ElapsedTicks" }, { "monotonic", true }, { "resolution", 1e-7 } }); |
| 130 | + case "time": |
| 131 | + return new SimpleNamespace(new Dictionary<string, object?> { { "adjustable", true }, { "implementation", "DateTime.Now" }, { "monotonic", false }, { "resolution", 0.015625 } }); |
| 132 | + default: |
| 133 | + throw PythonOps.ValueError("unknown clock"); |
| 134 | + } |
121 | 135 | } |
122 | 136 |
|
123 | 137 | public static void sleep(double tm) { |
|
0 commit comments