github.com/dubbogo/gost@v1.14.0/container/gxlru/perf_test.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 /* 18 * Licensed to the Apache Software Foundation (ASF) under one or more 19 * contributor license agreements. See the NOTICE file distributed with 20 * this work for additional information regarding copyright ownership. 21 * The ASF licenses this file to You under the Apache License, Version 2.0 22 * (the "License"); you may not use this file except in compliance with 23 * the License. You may obtain a copy of the License at 24 * 25 * http://www.apache.org/licenses/LICENSE-2.0 26 * 27 * Unless required by applicable law or agreed to in writing, software 28 * distributed under the License is distributed on an "AS IS" BASIS, 29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 30 * See the License for the specific language governing permissions and 31 * limitations under the License. 32 */ 33 34 package gxlru 35 36 import ( 37 "testing" 38 ) 39 40 type MyValue []byte 41 42 func (mv MyValue) Size() int { 43 return cap(mv) 44 } 45 46 func BenchmarkGet(b *testing.B) { 47 cache := NewLRUCache(64 * 1024 * 1024) 48 value := make(MyValue, 1000) 49 cache.Set("stuff", value) 50 for i := 0; i < b.N; i++ { 51 val, ok := cache.Get("stuff") 52 if !ok { 53 panic("error") 54 } 55 _ = val 56 } 57 }