Skip to content

Instantly share code, notes, and snippets.

@llimllib

llimllib/output Secret

Created September 7, 2019 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llimllib/72f60aa33b32e422962d876ddf0a4660 to your computer and use it in GitHub Desktop.
Save llimllib/72f60aa33b32e422962d876ddf0a4660 to your computer and use it in GitHub Desktop.
:$ 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