-
Notifications
You must be signed in to change notification settings - Fork 0
/
md5_test.go
69 lines (57 loc) · 1.37 KB
/
md5_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package sysutil
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"testing"
)
func Test(t *testing.T) {
if md5_OpenFalcon("1234567890123") != "ee76971984d25138a199ac90553401dd" {
t.FailNow()
}
if md5_EncodeToString_Write_string("1234567890123") != "ee76971984d25138a199ac90553401dd" {
t.FailNow()
}
if md5_EncodeToString_Write_byte("1234567890123") != "ee76971984d25138a199ac90553401dd" {
t.FailNow()
}
if Md5("1234567890123") != "ee76971984d25138a199ac90553401dd" {
t.FailNow()
}
}
func Benchmark_md5_OpenFalcon(b *testing.B) {
for i := 0; i < b.N; i++ {
md5_OpenFalcon("1234567890123")
}
}
func Benchmark_md5_EncodeToString_Write_string(b *testing.B) {
for i := 0; i < b.N; i++ {
md5_EncodeToString_Write_string("1234567890123")
}
}
func Benchmark_md5_EncodeToString_Write_byte(b *testing.B) {
for i := 0; i < b.N; i++ {
md5_EncodeToString_Write_byte("1234567890123")
}
}
func Benchmark_Md5(b *testing.B) {
for i := 0; i < b.N; i++ {
Md5("1234567890123")
}
}
func md5_OpenFalcon(raw string) string {
h := md5.New()
io.WriteString(h, raw)
return fmt.Sprintf("%x", h.Sum(nil))
}
func md5_EncodeToString_Write_string(raw string) string {
h := md5.New()
io.WriteString(h, raw)
return hex.EncodeToString(h.Sum(nil))
}
func md5_EncodeToString_Write_byte(raw string) string {
h := md5.New()
h.Write([]byte(raw))
return hex.EncodeToString(h.Sum(nil))
}