From b0c844415d65a209930a34e2f16ad8ae54229ffe Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 30 Jun 2019 14:35:26 +0200 Subject: [PATCH] time.ticks() on Linux/macOS --- compiler/main.v | 5 +++++ compiler/scanner.v | 2 +- vlib/time/time.v | 12 +++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index fa798c3bcd..4dea930c40 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -405,6 +405,7 @@ string _STR_TMP(const char *fmt, ...) { } fn (c mut V) cc() { + ticks := time.ticks() linux_host := os.user_os() == 'linux' c.log('cc() isprod=$c.is_prod outname=$c.out_name') mut a := ['-w']// arguments for the C compiler @@ -530,6 +531,10 @@ mut args := '' } println('linux cross compilation done. resulting binary: "$c.out_name"') } + if c.show_c_cmd { + diff := time.ticks() - ticks + println('cc() took $diff ms ') + } //os.rm('$TmpPath/$c.out_name_c') } diff --git a/compiler/scanner.v b/compiler/scanner.v index 923bd7287c..b0959f7b62 100644 --- a/compiler/scanner.v +++ b/compiler/scanner.v @@ -25,7 +25,7 @@ mut: const ( SINGLE_QUOTE = `\'` - QUOTE = `"` + //QUOTE = `"` ) fn new_scanner(file_path string) *Scanner { diff --git a/vlib/time/time.v b/vlib/time/time.v index 547f359ae3..49f592bff8 100644 --- a/vlib/time/time.v +++ b/vlib/time/time.v @@ -273,18 +273,24 @@ pub fn (t Time) weekday_str() string { return Days.substr(i * 3, (i + 1) * 3) } +struct C.timeval { + tv_sec int + tv_usec int +} + // in ms -pub fn ticks() f64 { +pub fn ticks() i64 { $if windows { return C.GetTickCount() } - panic('not implemented') + ts := C.timeval{} + C.gettimeofday(&ts,0) + return ts.tv_sec * 1000 + (ts.tv_usec / 1000) /* t := i64(C.mach_absolute_time()) # Nanoseconds elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &t ); # return (double)(* (uint64_t *) &elapsedNano) / 1000000; */ - return f64(0) } pub fn sleep(seconds int) {