From 4ef3a65ce6d40dc4e27df84b99668977ccbc8c42 Mon Sep 17 00:00:00 2001 From: Phil Opaola Date: Wed, 30 May 2018 01:16:41 -0400 Subject: [PATCH] Add benchmarks for partitioning with different Cluster sizes (#3) --- kmeans_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kmeans_test.go b/kmeans_test.go index 9ddc754..cea6071 100644 --- a/kmeans_test.go +++ b/kmeans_test.go @@ -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) }