Added duration
This commit is contained in:
parent
1da93e8406
commit
8a17a40e0c
11
main.go
11
main.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue