1 module tests.time; 2 3 4 version (WebAssembly) 5 { 6 alias int time_t; 7 alias int clockid_t; 8 enum CLOCK_REALTIME = 0; 9 10 struct timespec 11 { 12 time_t tv_sec; 13 int tv_nsec; 14 } 15 16 extern (C) int clock_gettime(clockid_t, timespec*) @nogc nothrow @system; 17 18 struct Time 19 { 20 static long getUSecTime() 21 { 22 time_t time; 23 timespec spec; 24 25 clock_gettime(CLOCK_REALTIME, &spec); 26 27 //time = spec.tv_sec; 28 return spec.tv_sec * 1000_000 + spec.tv_nsec / 1000; //time / 1000_000; 29 } 30 } 31 } 32 else version (Windows) 33 { 34 import core.stdc.stdio : printf; 35 import core.sys.windows.windows; 36 37 struct Time 38 { 39 static long getUSecTime() 40 { 41 LARGE_INTEGER time, freq; 42 QueryPerformanceFrequency(&freq); 43 QueryPerformanceCounter(&time); 44 return time.QuadPart / (freq.QuadPart / 1000_000); 45 } 46 } 47 } 48 else version (Posix) 49 { 50 import core.stdc.stdio : printf; 51 import core.sys.posix.time; 52 53 struct Time 54 { 55 static long getUSecTime() 56 { 57 time_t time; 58 timespec spec; 59 60 clock_gettime(CLOCK_REALTIME, &spec); 61 62 //time = spec.tv_sec; 63 return spec.tv_sec * 1000_000 + spec.tv_nsec / 1000; //time / 1000_000; 64 } 65 } 66 }