-
-
Save llimllib/72f60aa33b32e422962d876ddf0a4660 to your computer and use it in GitHub Desktop.
This file contains 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
:$ cat /tmp/main.go && go build -o /tmp/sha1 /tmp/main.go && /tmp/sha1 | |
package main | |
import ( | |
"crypto/sha1" | |
"fmt" | |
"io" | |
"math/rand" | |
"time" | |
) | |
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
func randStringBytes(n int) string { | |
b := make([]byte, n) | |
for i := range b { | |
b[i] = letterBytes[rand.Intn(len(letterBytes))] | |
} | |
return string(b) | |
} | |
func main() { | |
n := 1_000_000 | |
bytes := 100 | |
strings := make([]string, n, n) | |
for i := 0; i < n; i++ { | |
strings[i] = randStringBytes(bytes) | |
} | |
start := time.Now() | |
for _, s := range strings { | |
h := sha1.New() | |
io.WriteString(h, s) | |
h.Sum(nil) | |
} | |
finish := time.Now() | |
fmt.Printf("%v\n", finish.Sub(start)) | |
} | |
492.378102ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment