2011-06-04 19:00:53 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package rollsum
|
|
|
|
|
|
|
|
import (
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"math/rand"
|
2011-06-04 19:00:53 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSum(t *testing.T) {
|
|
|
|
var buf [100000]uint8
|
|
|
|
rnd := rand.New(rand.NewSource(4))
|
|
|
|
for i := range buf {
|
|
|
|
buf[i] = uint8(rnd.Intn(256))
|
|
|
|
}
|
|
|
|
|
|
|
|
sum := func(offset, len int) uint32 {
|
2011-06-04 23:14:33 +00:00
|
|
|
rs := New()
|
2011-06-04 19:00:53 +00:00
|
|
|
for count := offset; count < len; count++ {
|
|
|
|
rs.Roll(buf[count])
|
|
|
|
}
|
|
|
|
return rs.Digest()
|
|
|
|
}
|
|
|
|
|
|
|
|
sum1a := sum(0, len(buf))
|
|
|
|
sum1b := sum(1, len(buf))
|
|
|
|
sum2a := sum(len(buf)-windowSize*5/2, len(buf)-windowSize)
|
|
|
|
sum2b := sum(0, len(buf)-windowSize)
|
|
|
|
sum3a := sum(0, windowSize+3)
|
|
|
|
sum3b := sum(3, windowSize+3)
|
|
|
|
|
|
|
|
if sum1a != sum1b {
|
|
|
|
t.Errorf("sum1a=%d sum1b=%d", sum1a, sum1b)
|
|
|
|
}
|
|
|
|
if sum2a != sum2b {
|
|
|
|
t.Errorf("sum2a=%d sum2b=%d", sum2a, sum2b)
|
|
|
|
}
|
|
|
|
if sum3a != sum3b {
|
|
|
|
t.Errorf("sum3a=%d sum3b=%d", sum3a, sum3b)
|
|
|
|
}
|
|
|
|
}
|
2011-06-07 02:09:58 +00:00
|
|
|
|
|
|
|
func BenchmarkRollsum(b *testing.B) {
|
|
|
|
bytesSize := int64(1024 * 1024 * 5)
|
|
|
|
rs := New()
|
2012-10-28 12:07:42 +00:00
|
|
|
splits := 0
|
2011-06-07 02:09:58 +00:00
|
|
|
for i := 0; i < b.N; i++ {
|
2012-10-28 12:07:42 +00:00
|
|
|
splits = 0
|
2011-06-07 02:09:58 +00:00
|
|
|
for j := int64(0); j < bytesSize; j++ {
|
|
|
|
rs.Roll(byte(rand.Int63() & 0xff))
|
|
|
|
if rs.OnSplit() {
|
2012-10-28 12:07:42 +00:00
|
|
|
_ = rs.Bits()
|
|
|
|
splits++
|
2011-06-07 02:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b.SetBytes(bytesSize)
|
2012-10-28 12:07:42 +00:00
|
|
|
b.Logf("num splits = %d; every %d bytes", splits, int(float64(bytesSize) / float64(splits)))
|
2011-06-07 02:09:58 +00:00
|
|
|
}
|