Created
July 5, 2018 14:44
-
-
Save henriquechehad/3692a2818670881252608fd788b68243 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
Code: | |
============================================================ | |
package main | |
import ( | |
"log" | |
"sync" | |
"github.com/pkg/profile" | |
"golang.org/x/crypto/bcrypt" | |
) | |
func main() { | |
p := profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook) | |
defer p.Stop() | |
var wg sync.WaitGroup | |
for i := 0; i <= 500; i++ { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
err := bcrypt.CompareHashAndPassword([]byte("$2a$10$Q1bGQ4ERi4Zj.slbReOjOu0/T.2MhLCX9ASvCQqfh1LgbdRLdO6o6"), []byte("12345678")) | |
if err != nil { | |
log.Printf("error on compare: %v", err) | |
} | |
}() | |
} | |
wg.Wait() | |
log.Printf("DONE") | |
} | |
============================================================ | |
Results: | |
$ go tool pprof /Users/henriquechehad/go/src/github.com/henriquechehad/benchmark-bcrypt/benchmark-bcrypt /Users/henriquechehad/go/src/github.com/henriquechehad/benchmark-bcrypt/mem.pprof | |
File: benchmark-bcrypt | |
Type: inuse_space | |
Time: Jul 5, 2018 at 11:42am (BRT) | |
Entering interactive mode (type "help" for commands, "o" for options) | |
(pprof) | |
(pprof) top | |
Showing nodes accounting for 3740.70kB, 99.41% of 3763.08kB total | |
Dropped 3 nodes (cum <= 18.81kB) | |
Showing top 10 nodes out of 13 | |
flat flat% sum% cum cum% | |
3424.02kB 90.99% 90.99% 3424.02kB 90.99% vendor/golang.org/x/crypto/blowfish.NewSaltedCipher /Users/henriquechehad/go/src/vendor/golang.org/x/crypto/blowfish/cipher.go | |
88.59kB 2.35% 93.34% 92.60kB 2.46% vendor/golang.org/x/crypto/bcrypt.(*hashed).Hash /Users/henriquechehad/go/src/vendor/golang.org/x/crypto/bcrypt/bcrypt.go | |
67.05kB 1.78% 95.13% 67.05kB 1.78% runtime.malg /usr/local/go/src/runtime/proc.go | |
64.42kB 1.71% 96.84% 64.42kB 1.71% vendor/golang.org/x/crypto/bcrypt.newFromHash /Users/henriquechehad/go/src/vendor/golang.org/x/crypto/bcrypt/bcrypt.go | |
36.28kB 0.96% 97.80% 3661.49kB 97.30% main.main.func1 /Users/henriquechehad/go/src/github.com/henriquechehad/benchmark-bcrypt/main.go | |
28.22kB 0.75% 98.55% 101.59kB 2.70% runtime.systemstack /usr/local/go/src/runtime/asm_amd64.s | |
28.11kB 0.75% 99.30% 28.11kB 0.75% vendor/golang.org/x/crypto/bcrypt.base64Encode /Users/henriquechehad/go/src/vendor/golang.org/x/crypto/bcrypt/base64.go | |
4.02kB 0.11% 99.41% 3468.19kB 92.16% vendor/golang.org/x/crypto/bcrypt.bcrypt /Users/henriquechehad/go/src/vendor/golang.org/x/crypto/bcrypt/bcrypt.go | |
0 0% 99.41% 101.59kB 2.70% runtime.mstart /usr/local/go/src/runtime/proc.go | |
0 0% 99.41% 73.37kB 1.95% runtime.newproc.func1 /usr/local/go/src/runtime/proc.go | |
(pprof) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment