Bladeren bron

[python] use timeit module for best available timer resolution

frabbit 9 jaren geleden
bovenliggende
commit
e0e085392f
3 gewijzigde bestanden met toevoegingen van 10 en 2 verwijderingen
  1. 3 0
      std/haxe/Timer.hx
  2. 2 2
      std/python/_std/Sys.hx
  3. 5 0
      std/python/lib/Timeit.hx

+ 3 - 0
std/haxe/Timer.hx

@@ -175,8 +175,11 @@ class Timer {
 			return Date.now().getTime() / 1000;
 		#elseif cpp
 			return untyped __global__.__time_stamp();
+		#elseif python
+			return Sys.cpuTime();
 		#elseif sys
 			return Sys.time();
+		
 		#else
 			return 0;
 		#end

+ 2 - 2
std/python/_std/Sys.hx

@@ -107,8 +107,8 @@ class Sys {
 				python.lib.Subprocess.call([cmd].concat(args));
 	}
 
-	public static function cpuTime() : Float {
-		return python.lib.Time.clock();
+	public static inline function cpuTime() : Float {
+		return python.lib.Timeit.default_timer();
 	}
 
 	@:deprecated("Use programPath instead") public static function executablePath() : String {

+ 5 - 0
std/python/lib/Timeit.hx

@@ -0,0 +1,5 @@
+package python.lib;
+@:pythonImport("timeit")
+extern class Timeit {
+	public static function default_timer():Float;
+}