mirror of
https://github.com/muesli/kmeans.git
synced 2025-09-27 03:56:17 +08:00
Add benchmarks for partitioning with different Cluster sizes (#3)
This commit is contained in:

committed by
Christian Muehlhaeuser

parent
eaeb5a110c
commit
4ef3a65ce6
@@ -1,9 +1,12 @@
|
||||
package kmeans
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var RANDOM_SEED = int64(42)
|
||||
|
||||
func TestNewErrors(t *testing.T) {
|
||||
_, err := NewWithOptions(0.00, nil)
|
||||
if err == nil {
|
||||
@@ -63,3 +66,26 @@ func TestDimensions(t *testing.T) {
|
||||
t.Errorf("Expected %d clusters, got: %d", k, len(clusters))
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkPartition(size, partitions int, b *testing.B) {
|
||||
rand.Seed(RANDOM_SEED)
|
||||
var d Points
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
d = append(d, Point{
|
||||
rand.Float64(),
|
||||
rand.Float64(),
|
||||
})
|
||||
}
|
||||
|
||||
for j := 0; j < b.N; j++ {
|
||||
km := New()
|
||||
km.Partition(d, partitions)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkPartition32Points(b *testing.B) { benchmarkPartition(32, 16, b) }
|
||||
func BenchmarkPartition512Points(b *testing.B) { benchmarkPartition(512, 16, b) }
|
||||
func BenchmarkPartition4096Points(b *testing.B) { benchmarkPartition(4096, 16, b) }
|
||||
func BenchmarkPartition65536Points(b *testing.B) { benchmarkPartition(65536, 16, b) }
|
||||
|
Reference in New Issue
Block a user