github.com/cs3org/reva/v2@v2.27.7/pkg/storage/utils/indexer/helper_test.go (about) 1 // Copyright 2018-2022 CERN 2 // 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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 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. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package indexer 20 21 import ( 22 "strconv" 23 "time" 24 25 . "github.com/onsi/ginkgo/v2" 26 . "github.com/onsi/gomega" 27 "github.com/onsi/gomega/gmeasure" 28 ) 29 30 var _ = Describe("Helper", func() { 31 Describe("dedup", func() { 32 It("dedups reasonably fast", func() { 33 experiment := gmeasure.NewExperiment("deduplicating string slices") 34 AddReportEntry(experiment.Name, experiment) 35 36 experiment.Sample(func(idx int) { 37 slice := []string{} 38 for i := 0; i < 900; i++ { 39 slice = append(slice, strconv.Itoa(i)) 40 } 41 for i := 0; i < 100; i++ { 42 slice = append(slice, strconv.Itoa(i)) 43 } 44 experiment.MeasureDuration("repagination", func() { 45 dedupped := dedup(slice) 46 Expect(len(dedupped)).To(Equal(900)) 47 }) 48 }, gmeasure.SamplingConfig{N: 100000, Duration: 10 * time.Second}) 49 50 repaginationStats := experiment.GetStats("repagination") 51 medianDuration := repaginationStats.DurationFor(gmeasure.StatMedian) 52 Expect(medianDuration).To(BeNumerically("<", 1200*time.Microsecond)) 53 }) 54 }) 55 })