1 // Copyright 2014 Google Inc.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
17 // This binary compares memory usage between btree and gollrb.
27 "github.com/google/btree"
28 "github.com/petar/GoLLRB/llrb"
32 size = flag.Int("size", 1000000, "size of the tree to build")
33 degree = flag.Int("degree", 8, "degree of btree")
34 gollrb = flag.Bool("llrb", false, "use llrb instead of btree")
39 vals := rand.Perm(*size)
42 var stats runtime.MemStats
43 for i := 0; i < 10; i++ {
46 fmt.Println("-------- BEFORE ----------")
47 runtime.ReadMemStats(&stats)
48 fmt.Printf("%+v\n", stats)
52 for _, v := range vals {
53 tr.ReplaceOrInsert(llrb.Int(v))
55 t = tr // keep it around
57 tr := btree.New(*degree)
58 for _, v := range vals {
59 tr.ReplaceOrInsert(btree.Int(v))
61 t = tr // keep it around
63 fmt.Printf("%v inserts in %v\n", *size, time.Since(start))
64 fmt.Println("-------- AFTER ----------")
65 runtime.ReadMemStats(&stats)
66 fmt.Printf("%+v\n", stats)
67 for i := 0; i < 10; i++ {
70 fmt.Println("-------- AFTER GC ----------")
71 runtime.ReadMemStats(&stats)
72 fmt.Printf("%+v\n", stats)
74 fmt.Println("to make sure vals and tree aren't GC'd")