Example #1
0
func benchmarkUnpack(trials int,
	chunks *chunks,
	fpack func(interface{}) *bp128.PackedInts,
	funpack func(*bp128.PackedInts, interface{})) int {

	packed := make([]*bp128.PackedInts, len(chunks.data))
	for i, c := range chunks.data {
		packed[i] = fpack(c)
	}

	var out interface{}
	if chunks.intSize == 32 {
		out = &[]uint32{}
		bp128.MakeAlignedSlice(chunkByteSize/4, out)
	} else if chunks.intSize == 64 {
		out = &[]uint64{}
		bp128.MakeAlignedSlice(chunkByteSize/8, out)
	}

	times := make([]int, trials)
	for i := range times {
		start := time.Now()
		for _, p := range packed {
			funpack(p, out)
		}
		times[i] = int(time.Since(start).Nanoseconds())
	}

	// Check if both input and output are equal
	for i, c := range chunks.data {
		funpack(packed[i], out)

		vc := reflect.ValueOf(c)
		vo := reflect.ValueOf(out).Elem()
		for j := 0; j < vc.Len(); j++ {
			if vc.Index(j).Uint() != vo.Index(j).Uint() {
				panic("whoops! something went wrong")
			}
		}
	}

	sort.Ints(times)
	tmedian := times[len(times)/2]
	speed := (float64(chunks.length) / float64(tmedian)) * 1e3

	return int(speed)
}
Example #2
0
func chunkify64(data []int) *chunks {
	const chunkLen = chunkByteSize / 8

	nchunks := len(data) / chunkLen
	cdata := make([]interface{}, nchunks)

	n := 0
	for i := range cdata {
		chunk := []uint64{}
		bp128.MakeAlignedSlice(chunkLen, &chunk)
		for j := range chunk {
			chunk[j] = uint64(data[n])
			n++
		}
		cdata[i] = chunk
	}

	return &chunks{64, cdata, n}
}