mirror of https://github.com/curusarn/resh
I have benchmarked: - 'date +%s.%N' -> 1.3ms - 'resh-get-epochtime' -> 2.1ms - 'date --version' -> 1.1ms This means that it's better to run the Go binary once than running 'date' multiple times to check that it is installed and then to get the time. Also it's just much simpler and robust to have one binary instead of shell function with multiple if-else branches.pull/184/head
parent
bc78fed469
commit
cb5e01bd07
@ -0,0 +1,17 @@ |
|||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"time" |
||||||
|
) |
||||||
|
|
||||||
|
// Small utility to get epochtime in millisecond precision
|
||||||
|
// Doesn't check arguments
|
||||||
|
// Exits with status 1 on error
|
||||||
|
func main() { |
||||||
|
fmt.Printf("%s", timeToEpochTime(time.Now())) |
||||||
|
} |
||||||
|
|
||||||
|
func timeToEpochTime(t time.Time) string { |
||||||
|
return fmt.Sprintf("%.2f", float64(t.UnixMilli())/1000) |
||||||
|
} |
||||||
Loading…
Reference in new issue