Skip to content

Instantly share code, notes, and snippets.

@Israel-Miles
Last active September 27, 2021 15:07
Show Gist options
  • Save Israel-Miles/6e7ab97f8de319675d7bacaeab750653 to your computer and use it in GitHub Desktop.
Save Israel-Miles/6e7ab97f8de319675d7bacaeab750653 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
var cache = map[int]int{}
var database = make(map[int]int, 1000)
func main() {
generateRandomDatabase()
start := time.Now()
var wg sync.WaitGroup
var mtx sync.RWMutex
for i := 0; i < 10000; i++ {
wg.Add(1)
go GetValue(i, &wg, &mtx)
}
wg.Wait()
fmt.Println("Total execution time:", time.Since(start))
}
func generateRandomDatabase() {
for i := 0; i < len(database); i++ {
database[i] = rand.Int()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment