Added duration

This commit is contained in:
konrad 2019-04-07 14:10:37 +02:00
parent 1da93e8406
commit 8a17a40e0c
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 7 additions and 4 deletions

11
main.go
View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"sort"
"time"
)
func main() {
@ -19,11 +20,12 @@ func main() {
m[8] = 88
m[9] = 99
start := time.Now()
iterations := 0
var slice []int
var sorted = false
for !sorted {
for !sorted {
// We put the map in a slice to have something more deterministic to work with
slice = nil
for _, msg := range m {
@ -43,10 +45,11 @@ func main() {
fmt.Printf("\rIteration %d, no miracle happened yet.", iterations)
}
fmt.Println("Sorted.")
fmt.Println("Iterations: ", iterations)
fmt.Println("\nSorted.")
fmt.Printf("Took %v\n", time.Since(start))
fmt.Printf("Iterations: %d\n", iterations)
fmt.Println("MAP:")
fmt.Println("Sorted slice:")
for index, msg := range slice {
fmt.Println(index, ": ", msg)
}