2020-10-28 17:00:21 +00:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
package database_test
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
"github.com/mudler/luet/pkg/api/core/types"
|
|
|
|
. "github.com/mudler/luet/pkg/database"
|
2021-12-31 20:01:40 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2020-10-28 17:00:21 +00:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Database benchmark", func() {
|
|
|
|
|
|
|
|
Context("BoltDB", func() {
|
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
a := types.NewPackage("A", ">=1.0", []*types.Package{}, []*types.Package{})
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
tmpfile, _ := ioutil.TempFile(os.TempDir(), "tests")
|
|
|
|
defer os.Remove(tmpfile.Name()) // clean up
|
2022-01-06 22:57:56 +00:00
|
|
|
var db types.PackageSet
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
|
|
|
|
tmpfile, _ = ioutil.TempFile(os.TempDir(), "tests")
|
|
|
|
defer os.Remove(tmpfile.Name()) // clean up
|
|
|
|
db = NewBoltDatabase(tmpfile.Name())
|
2020-10-28 19:30:26 +00:00
|
|
|
if os.Getenv("BENCHMARK_TESTS") != "true" {
|
|
|
|
Skip("BENCHMARK_TESTS not enabled")
|
|
|
|
}
|
2020-10-28 17:00:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Measure("it should be fast in computing world from a 50000 dataset", func(b Benchmarker) {
|
|
|
|
for i := 0; i < 50000; i++ {
|
2022-01-06 22:57:56 +00:00
|
|
|
a = types.NewPackage("A"+strconv.Itoa(i), ">=1.0", []*types.Package{}, []*types.Package{})
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
_, err := db.CreatePackage(a)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
}
|
|
|
|
runtime := b.Time("runtime", func() {
|
|
|
|
packs := db.World()
|
|
|
|
Expect(len(packs)).To(Equal(50000))
|
|
|
|
})
|
|
|
|
|
2020-10-28 19:30:26 +00:00
|
|
|
Ω(runtime.Seconds()).Should(BeNumerically("<", 30), "World() shouldn't take too long.")
|
2020-10-28 17:00:21 +00:00
|
|
|
|
2020-10-28 19:30:26 +00:00
|
|
|
}, 1)
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
Measure("it should be fast in computing world from a 100000 dataset", func(b Benchmarker) {
|
|
|
|
for i := 0; i < 100000; i++ {
|
2022-01-06 22:57:56 +00:00
|
|
|
a = types.NewPackage("A"+strconv.Itoa(i), ">=1.0", []*types.Package{}, []*types.Package{})
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
_, err := db.CreatePackage(a)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
}
|
|
|
|
runtime := b.Time("runtime", func() {
|
|
|
|
packs := db.World()
|
|
|
|
Expect(len(packs)).To(Equal(100000))
|
|
|
|
})
|
|
|
|
|
2020-10-28 19:30:26 +00:00
|
|
|
Ω(runtime.Seconds()).Should(BeNumerically("<", 30), "World() shouldn't take too long.")
|
2020-10-28 17:00:21 +00:00
|
|
|
|
2020-10-28 19:30:26 +00:00
|
|
|
}, 1)
|
2020-10-28 17:00:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Context("InMemory", func() {
|
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
a := types.NewPackage("A", ">=1.0", []*types.Package{}, []*types.Package{})
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
tmpfile, _ := ioutil.TempFile(os.TempDir(), "tests")
|
|
|
|
defer os.Remove(tmpfile.Name()) // clean up
|
2022-01-06 22:57:56 +00:00
|
|
|
var db types.PackageSet
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
|
|
|
|
tmpfile, _ = ioutil.TempFile(os.TempDir(), "tests")
|
|
|
|
defer os.Remove(tmpfile.Name()) // clean up
|
|
|
|
db = NewInMemoryDatabase(false)
|
2020-10-28 19:30:26 +00:00
|
|
|
if os.Getenv("BENCHMARK_TESTS") != "true" {
|
|
|
|
Skip("BENCHMARK_TESTS not enabled")
|
|
|
|
}
|
2020-10-28 17:00:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Measure("it should be fast in computing world from a 100000 dataset", func(b Benchmarker) {
|
|
|
|
|
|
|
|
runtime := b.Time("runtime", func() {
|
|
|
|
for i := 0; i < 100000; i++ {
|
2022-01-06 22:57:56 +00:00
|
|
|
a = types.NewPackage("A"+strconv.Itoa(i), ">=1.0", []*types.Package{}, []*types.Package{})
|
2020-10-28 17:00:21 +00:00
|
|
|
|
|
|
|
_, err := db.CreatePackage(a)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
}
|
|
|
|
packs := db.World()
|
|
|
|
Expect(len(packs)).To(Equal(100000))
|
|
|
|
})
|
|
|
|
|
2020-10-28 19:30:26 +00:00
|
|
|
Ω(runtime.Seconds()).Should(BeNumerically("<", 10), "World() shouldn't take too long.")
|
2020-10-28 17:00:21 +00:00
|
|
|
|
2020-10-28 19:30:26 +00:00
|
|
|
}, 2)
|
2020-10-28 17:00:21 +00:00
|
|
|
})
|
|
|
|
})
|