Skip to content

Conversation

nicktming
Copy link

Since forwardMap key is the start point, value is the length starting with the key, then we just sort the key to make the whole array sorted instead of sorting the whole array.

This is my performance test compared with these two algorithms:

  1. N: is the number of forwardMap key
  2. val: is the value of each key
  3. time_used_origin: is the time used of the origin function
  4. time_used_new: is the time used of the improved function
N val time_used_origin time_used_new
10000 1 2.301202ms 2.614463ms
10000 10 18.204936ms 2.942327ms
10000 100 164.167666ms 7.275755ms
10000 1000 1.71088519s 115.790789ms
10000 10000 19.85861009s 1.625219654s
func main() {
	N := int32(10000)
	fm := make(map[pgid]uint64)
	i := int32(0)
	val := int32(0)
	for i = 0; i < N;  {
		val = rand.Int31n(1000)
		fm[pgid(i)] = uint64(val)
		i += val
	}

	f := freelist{
		forwardMap: fm,
	}
	start := time.Now()
	f.hashmapGetFreePageIDs()
	end := time.Now()
	fmt.Printf("origin time:%v\n", end.Sub(start))

	start = time.Now()
	res := f.newHashmapGetFreePageIDs()
	end = time.Now()
	fmt.Printf("new time:%v\n", end.Sub(start))


	if !sort.SliceIsSorted(res, func(i, j int) bool { return res[i] < res[j] }) {
		panic("pgids not sorted")
	}
}

based on the above testing program, when changing N, got the following result compared with two functions

N time_used_origin time_used_new
100 71.608µs 9.022µs
1000 226.745µs 19.359µs
10000 1.290836ms 77.194µs
100000 15.973611ms 777.995µs
1000000 160.912048ms 5.714576ms
10000000 1.789962277s 99.443407ms

@nicktming nicktming closed this Apr 28, 2020
@nicktming nicktming deleted the bbolt-trasval branch April 28, 2020 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant