Skip to content

Commit

Permalink
jenkins3 -> jenkins, got some gen2 functions working
Browse files Browse the repository at this point in the history
  • Loading branch information
tildeleb committed Dec 4, 2014
1 parent 9e6fa55 commit d4e4b4e
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 173 deletions.
87 changes: 50 additions & 37 deletions jenkins3/example/example.go → jenkins/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import "log"
import "runtime/pprof"
//import "math/rand"
//import "runtime"
import "github.com/tildeleb/hashes/jenkins3"
import "github.com/tildeleb/hashes/jenkins"
import "github.com/tildeleb/hrff"

func stu(s string) (u []uint32) {
fmt.Printf("stu: s=%q\n", s)
func stu(s string) []uint32 {
//fmt.Printf("stu: s=%q\n", s)
l := (len(s) + 3) / 4
d := make([]uint32, l, l)
d = d[0:0]
b := ([]byte)(s)
fmt.Printf("b=%x\n", b)
for i := 0; i < l; i += 4 {
//fmt.Printf("b=%x\n", b)
for i := 0; i < l; i++ {
t := *(*uint32)(unsafe.Pointer(&b[i*4]))
fmt.Printf("t=%x \n", t)
//fmt.Printf("t=%x \n", t)
d = append(d, t)
}
fmt.Printf("stu: d=%x\n", d)
//fmt.Printf("stu: len(s)=%d, len(d)=%d, d=%x\n", len(s), len(d), d)
return d
}

Expand Down Expand Up @@ -84,11 +84,11 @@ func driver2() {
/* have a and b be two keys differing in only one bit */
a[i] ^= byte(k<<j)
a[i] ^= byte(k>>(8-j))
c[0] = jenkins3.HashBytesLength(a, hlen, m)
c[0] = jenkins.HashBytesLength(a, hlen, m)

b[i] ^= byte((k+1)<<j)
b[i] ^= byte((k+1)>>(8-j))
d[0] = jenkins3.HashBytesLength(b, hlen, m)
d[0] = jenkins.HashBytesLength(b, hlen, m)
// check every bit is 1, 0, set, and not set at least once
for l := 0; l < HASHSTATE; l++ {
e[l] &= (c[l]^d[l])
Expand Down Expand Up @@ -193,28 +193,36 @@ func tdiff(begin, end time.Time) time.Duration {
}


func benchmark64(n int) {
func benchmark64(n int64) {
var hashes = make(Uint64Slice, n)
var u = make([]uint64, 1, 1)
fmt.Printf("benchmark64: gen n=%d, n=%h, size=%H\n", n, n, n*8)
bs := make([]byte, 24, 24)

fmt.Printf("benchmark64: gen n=%d, n=%h, size=%H\n", n, hrff.Int64{n, ""}, hrff.Int64{n*8, "B"})
start := time.Now()
for i := 0; i < n; i++ {
u[0] = uint64(i)
h := jenkins3.HashWords64(u, 1, 0)
for i := int64(0); i < n; i++ {
bs[0], bs[1], bs[2], bs[3] = byte(i&0xFF), byte((i>>8)&0xFF), byte((i>>16)&0xFF), byte((i>>24)&0xFF)
bs[4], bs[5], bs[6], bs[7] = bs[0], bs[1], bs[2], bs[3]
bs[8], bs[9], bs[10], bs[11], bs[12], bs[13], bs[14], bs[15] = bs[0], bs[1], bs[2], bs[3], bs[4], bs[5], bs[6], bs[7]
bs[16], bs[17], bs[18], bs[19], bs[20], bs[21], bs[22], bs[23] = bs[0], bs[1], bs[2], bs[3], bs[4], bs[5], bs[6], bs[7]
h := jenkins.Hash264(bs, 0)
hashes[i] = h
//fmt.Printf("i=%d, 0x%08x, h=0x%08x\n", i, i, h)
//fmt.Printf("i=%d, 0x%08x, h=0x%016x\n", i, i, h)
}
stop := time.Now()
d := tdiff(start, stop)
hsec := hrff.Float64{(float64(n) / d.Seconds()), " hashes/sec"}
fmt.Printf("benchmark64: %H\n", hsec)
hsec := hrff.Float64{(float64(n) / d.Seconds()), "hashes/sec"}
bsec := hrff.Float64{(float64(n) * float64(24) / d.Seconds()), "B/sec"}
fmt.Printf("benchmark64: %h\n", hsec)
fmt.Printf("benchmark64: %h\n", bsec)
fmt.Printf("benchmark64: sort n=%d\n", n)
hashes.Sort()
/*
for i := 0; i < n; i++ {
fmt.Printf("i=%d, 0x%08x, h=0x%08x\n", i, i, hashes[i])

if false {
for i := int64(0); i < n; i++ {
fmt.Printf("i=%d, 0x%08x, h=0x%08x\n", i, i, hashes[i])
}
}
*/

fmt.Printf("benchmark64: dup check n=%d\n", n)
dups := checkForDups64(hashes)
fmt.Printf("benchmark64: dups=%d\n", dups)
Expand All @@ -226,21 +234,24 @@ func benchmark64(n int) {

func benchmark32(n int) {
//var hashes = make(Uint32Slice, n)
var u = make([]uint32, 1, 1)
//var u = make([]uint32, 1, 1)
bs := make([]byte, 4, 4)
var pn = hrff.Int64{int64(n), ""}
var ps = hrff.Int64{int64(n*4), "B"}
fmt.Printf("benchmark32: gen n=%d, n=%h, size=%h\n", n, pn, ps)
start := time.Now()
for i := 0; i < n; i++ {
u[0] = uint32(i)
_ = jenkins3.HashWords32(u, 0)
bs[0], bs[1], bs[2], bs[3] = byte(i)&0xFF, (byte(i)>>8)&0xFF, (byte(i)>>16)&0xFF, (byte(i)>>24)&0xFF
_ = jenkins.Hash232(bs, 0)
//hashes[i] = h
//fmt.Printf("i=%d, 0x%08x, h=0x%08x\n", i, i, h)
}
stop := time.Now()
d := tdiff(start, stop)
hsec := hrff.Float64{(float64(n) / d.Seconds()), " hashes/sec"}
fmt.Printf("benchmark32: %H\n", hsec)
hsec := hrff.Float64{(float64(n) / d.Seconds()), "hashes/sec"}
bsec := hrff.Float64{(float64(n) * 4 / d.Seconds()), "B/sec"}
fmt.Printf("benchmark32: %h\n", hsec)
fmt.Printf("benchmark32: %h\n", bsec)
return

fmt.Printf("benchmark32: sort n=%d\n", n)
Expand All @@ -258,6 +269,7 @@ func benchmark32(n int) {
var n = flag.Int("n", 5, "number of hashes")
var p = flag.String("p", "", "write cpu profile to file")

/*
func ShortTest(n int) {
var u = make([]uint32, 1, 1)
Expand All @@ -267,6 +279,7 @@ func ShortTest(n int) {
fmt.Printf("i=%d, 0x%08x, h=0x%08x\n", i, i, h)
}
}
*/

func main() {
flag.Parse()
Expand All @@ -282,7 +295,7 @@ func main() {
//ShortTest(*n)
//return
benchmark32(*n)
//benchmark64(*n)
benchmark64(int64(*n))
return

q := "This is the time for all good men to come to the aid of their country..."
Expand All @@ -291,33 +304,33 @@ func main() {
//qqqq[] := []byte{"xxxThis is the time for all good men to come to the aid of their country..."}

u := stu(q)
h1 := jenkins3.HashWordsLen(u, (len(q)-1)/4, 13)
h2 := jenkins3.HashWordsLen(u, (len(q)-5)/4, 13)
h3 := jenkins3.HashWordsLen(u, (len(q)-9)/4, 13)
h1 := jenkins.HashWordsLen(u, (len(q)-1)/4, 13)
h2 := jenkins.HashWordsLen(u, (len(q)-5)/4, 13)
h3 := jenkins.HashWordsLen(u, (len(q)-9)/4, 13)
fmt.Printf("%08x, %08x, %08x\n", h1, h2, h3)

b, c := uint32(0), uint32(0)
c, b = jenkins3.HashString("", c, b)
c, b = jenkins.HashString("", c, b)
fmt.Printf("%08x, %08x\n", c, b) // deadbeef deadbeef

b, c = 0xdeadbeef, 0
c, b = jenkins3.HashString("", c, b)
c, b = jenkins.HashString("", c, b)
fmt.Printf("%08x, %08x\n", c, b) // bd5b7dde deadbeef

b, c = 0xdeadbeef, 0xdeadbeef
c, b = jenkins3.HashString("", c, b)
c, b = jenkins.HashString("", c, b)
fmt.Printf("%08x, %08x\n", c, b) // 9c093ccd bd5b7dde

b, c = 0, 0
c, b = jenkins3.HashString("Four score and seven years ago", c, b)
c, b = jenkins.HashString("Four score and seven years ago", c, b)
fmt.Printf("%08x, %08x\n", c, b) // 17770551 ce7226e6

b, c = 1, 0
c, b = jenkins3.HashString("Four score and seven years ago", c, b)
c, b = jenkins.HashString("Four score and seven years ago", c, b)
fmt.Printf("%08x, %08x\n", c, b) // e3607cae bd371de4

b, c = 0, 1
c, b = jenkins3.HashString("Four score and seven years ago", c, b)
c, b = jenkins.HashString("Four score and seven years ago", c, b)
fmt.Printf("%08x, %08x\n", c, b) // cd628161 6cbea4b3

driver2()
Expand Down
Loading

0 comments on commit d4e4b4e

Please sign in to comment.