Last active
September 27, 2021 15:07
-
-
Save Israel-Miles/6e7ab97f8de319675d7bacaeab750653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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