mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-17 07:24:21 +01:00
removed old benchmarks and helper func
This commit is contained in:
@@ -4,8 +4,6 @@ package graph
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand/v2"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pippellia-btc/slicex"
|
"github.com/pippellia-btc/slicex"
|
||||||
@@ -69,8 +67,6 @@ type Delta struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewDelta returns a delta by computing the relationships to remove, keep and add.
|
// NewDelta returns a delta by computing the relationships to remove, keep and add.
|
||||||
// Time complexity O(n * logn + m * logm), where n and m are the lengths of the slices.
|
|
||||||
// This function is much faster than converting to sets for sizes (n, m) smaller than ~10^6.
|
|
||||||
func NewDelta(kind int, node ID, old, new []ID) Delta {
|
func NewDelta(kind int, node ID, old, new []ID) Delta {
|
||||||
delta := Delta{
|
delta := Delta{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
@@ -106,13 +102,3 @@ func (d Delta) Inverse() Delta {
|
|||||||
Add: d.Remove,
|
Add: d.Remove,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandomIDs of the provided size.
|
|
||||||
func RandomIDs(size int) []ID {
|
|
||||||
IDs := make([]ID, size)
|
|
||||||
for i := range size {
|
|
||||||
node := rand.IntN(10000000)
|
|
||||||
IDs[i] = ID(strconv.Itoa(node))
|
|
||||||
}
|
|
||||||
return IDs
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package graph
|
package graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -50,69 +49,3 @@ func TestNewDelta(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkNewDelta(b *testing.B) {
|
|
||||||
sizes := []int{1000, 10000, 100000}
|
|
||||||
for _, size := range sizes {
|
|
||||||
b.Run(fmt.Sprintf("size=%d", size), func(b *testing.B) {
|
|
||||||
old := RandomIDs(size)
|
|
||||||
new := RandomIDs(size)
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for range b.N {
|
|
||||||
NewDelta(3, "0", old, new)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkNewDeltaSets(b *testing.B) {
|
|
||||||
sizes := []int{1000, 10000, 100000}
|
|
||||||
for _, size := range sizes {
|
|
||||||
b.Run(fmt.Sprintf("size=%d", size), func(b *testing.B) {
|
|
||||||
old := RandomIDs(size)
|
|
||||||
new := RandomIDs(size)
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for range b.N {
|
|
||||||
newDeltaSet(3, "0", old, new)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newDeltaSet(kind int, node ID, old, new []ID) Delta {
|
|
||||||
delta := Delta{
|
|
||||||
Kind: kind,
|
|
||||||
Node: node,
|
|
||||||
}
|
|
||||||
|
|
||||||
oldMap := make(map[ID]struct{}, len(old))
|
|
||||||
newMap := make(map[ID]struct{}, len(new))
|
|
||||||
|
|
||||||
// Fill maps
|
|
||||||
for _, id := range old {
|
|
||||||
oldMap[id] = struct{}{}
|
|
||||||
}
|
|
||||||
for _, id := range new {
|
|
||||||
newMap[id] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find removed and kept
|
|
||||||
for _, id := range old {
|
|
||||||
if _, found := newMap[id]; found {
|
|
||||||
delta.Keep = append(delta.Keep, id)
|
|
||||||
} else {
|
|
||||||
delta.Remove = append(delta.Remove, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find added
|
|
||||||
for _, id := range new {
|
|
||||||
if _, found := oldMap[id]; !found {
|
|
||||||
delta.Add = append(delta.Add, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return delta
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user