示例#1
0
func Random() {
	fmt.Println("\n[benchmark 2]")

	e := elephantlist.NewIntList()
	s := skiplist.NewIntMap()

	query := rand.Perm(*n)
	eRandStart := time.Now()
	for _, x := range query {
		e.Set(x, x)
	}
	eRandDuration := time.Since(eRandStart)

	sRandStart := time.Now()
	for _, x := range query {
		s.Set(x, x)
	}
	sRandDuration := time.Since(sRandStart)

	fmt.Printf("random set %d elements\n", *n)
	fmt.Println("\telephantlist:\t", eRandDuration)
	fmt.Println("\tskiplist:\t", sRandDuration)

	query = rand.Perm(*n)
	eRandStart = time.Now()
	for _, x := range query {
		e.Get(x)
	}
	eRandDuration = time.Since(eRandStart)

	sRandStart = time.Now()
	for _, x := range query {
		s.Get(x)
	}
	sRandDuration = time.Since(sRandStart)
	fmt.Printf("random get %d elements\n", *n)
	fmt.Println("\telephantlist:\t", eRandDuration)
	fmt.Println("\tskiplist:\t", sRandDuration)
}
示例#2
0
func Sequential() {
	fmt.Println("\n[benchmark 1]")

	e := elephantlist.NewIntList()
	s := skiplist.NewIntMap()

	eSeqStart := time.Now()
	for i := 0; i < *n; i++ {
		e.Set(i, i)
	}
	eSeqDuration := time.Since(eSeqStart)

	sSeqStart := time.Now()
	for i := 0; i < *n; i++ {
		s.Set(i, i)
	}
	sSeqDuration := time.Since(sSeqStart)

	fmt.Printf("sequential set %d elements\n", *n)
	fmt.Println("\telephantlist:\t", eSeqDuration)
	fmt.Println("\tskiplist:\t", sSeqDuration)

	query := rand.Perm(*n)
	eSeqStart = time.Now()
	for _, x := range query {
		e.Get(x)
	}
	eSeqDuration = time.Since(eSeqStart)

	sSeqStart = time.Now()
	for _, x := range query {
		s.Get(x)
	}
	sSeqDuration = time.Since(sSeqStart)
	fmt.Printf("random get %d elements\n", *n)
	fmt.Println("\telephantlist:\t", eSeqDuration)
	fmt.Println("\tskiplist:\t", sSeqDuration)
}
示例#3
0
func New() *Instance {
	return &Instance{
		sl: skiplist.NewIntMap(),
	}
}
示例#4
0
func (this *calculator) Histogram2() (res *HistogramResult) {
	res = &HistogramResult{
		dist: skiplist.NewIntMap(),
		cdf:  skiplist.NewIntMap(),
	}

	min := int64(1e9)
	max := int64(0)

	// Copy our histogram map into an ordered skiplist.
	for usec, freq := range this.hist {
		if usec < min {
			min = usec
		}

		if usec > max {
			max = usec
		}

		v := []int{freq}
		if this.IsClientTrackingEnabled() {
			v = make([]int, this.clientCount+1)
			v[0] = freq
		}

		res.dist.Set(int(usec), v)
	}

	res.min = min
	res.max = max

	// Build the CDF.
	sum := int64(0)

	iter := res.dist.Iterator()
	for iter.Next() {
		usec := iter.Key().(int)
		vs := iter.Value().([]int)
		freq := int64(vs[0])

		sum += freq

		v := float64(sum) / float64(this.prev_ops_sum)

		switch {
		case res.p5 == 0 && v >= 0.05:
			res.p5 = usec
		case res.p95 == 0 && v >= 0.95:
			res.p95 = usec
		case res.p99 == 0 && v >= 0.99:
			res.p99 = usec
		}

		res.cdf.Set(usec, v)
	}

	// Extend the skiplist with per-client stats, if enabled.
	if this.IsClientTrackingEnabled() {
		for id, bucket := range this.clients {
			for usec, count := range bucket.hist {
				v, ok := res.dist.Get(int(usec))
				if ok {
					v.([]int)[id+1] = count
				}
			}
		}
	}

	return
}