56 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package md5helper
 | 
						|
 | 
						|
import (
 | 
						|
	"crypto/md5"
 | 
						|
	"encoding/hex"
 | 
						|
	"fmt"
 | 
						|
	"testing"
 | 
						|
)
 | 
						|
 | 
						|
func TestMD52(t *testing.T) {
 | 
						|
	got := MD52("Qq123456")
 | 
						|
	fmt.Println(got)
 | 
						|
}
 | 
						|
 | 
						|
func TestMD5(t *testing.T) {
 | 
						|
	got := []byte("Qq123456")
 | 
						|
	s := md5.New()
 | 
						|
	s.Write(got)
 | 
						|
	fmt.Println(hex.EncodeToString(s.Sum(nil)))
 | 
						|
 | 
						|
	cc := md5.Sum(got)
 | 
						|
	fmt.Println(hex.EncodeToString(cc[:]))
 | 
						|
 | 
						|
	fmt.Printf("%x\n", md5.Sum(got))
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
// go test -bench=_QE_ -benchmem -run=^$
 | 
						|
func Benchmark_QE_1(b *testing.B) {
 | 
						|
	for i := 0; i < b.N; i++ {
 | 
						|
		input := `Qq123456`
 | 
						|
		s := md5.New()
 | 
						|
		s.Write([]byte(input))
 | 
						|
		hex.EncodeToString(s.Sum(nil))
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func Benchmark_QE_2(b *testing.B) {
 | 
						|
	for i := 0; i < b.N; i++ {
 | 
						|
		input := `Qq123456`
 | 
						|
		cc := md5.Sum([]byte(input))
 | 
						|
		hex.EncodeToString(cc[:])
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func Benchmark_QE_3(b *testing.B) {
 | 
						|
	for i := 0; i < b.N; i++ {
 | 
						|
		input := `Qq123456`
 | 
						|
		fmt.Sprintf("%x\n", md5.Sum([]byte(input)))
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
// Benchmark_QE_1-6         6354160               189.8 ns/op            48 B/op          2 allocs/op
 | 
						|
// Benchmark_QE_2-6         7352328               162.9 ns/op            32 B/op          1 allocs/op
 | 
						|
// Benchmark_QE_3-6         3007480               396.9 ns/op            80 B/op          3 allocs/op
 |