diff --git a/pagerank.go b/pagerank.go index 49704d6..7392d1c 100644 --- a/pagerank.go +++ b/pagerank.go @@ -1,6 +1,9 @@ package pagerank -import "math" +import ( + "fmt" + "math" +) type Interface interface { Rank(followingProb, tolerance float64, resultFunc func(label int, rank float64)) @@ -21,6 +24,22 @@ func New() *pageRank { return pr } +func (pr *pageRank) String() string { + return fmt.Sprintf( + "PageRank Struct:\n"+ + "InLinks: %v\n"+ + "NumberOutLinks: %v\n"+ + "CurrentAvailableIndex: %d\n"+ + "KeyToIndex: %v\n"+ + "IndexToKey: %v", + pr.inLinks, + pr.numberOutLinks, + pr.currentAvailableIndex, + pr.keyToIndex, + pr.indexToKey, + ) +} + func (pr *pageRank) keyAsArrayIndex(key int) int { index, ok := pr.keyToIndex[key] diff --git a/pagerank_test.go b/pagerank_test.go index b50f34c..5949452 100644 --- a/pagerank_test.go +++ b/pagerank_test.go @@ -207,13 +207,11 @@ func TestShouldCorrectlyReproduceTheWikipediaExample(t *testing.T) { assertRank(t, pageRank, expectedRank) } -func BenchmarkOneMillion(b *testing.B) { - n := 1000000 +func BenchmarkOneHundredThousand(b *testing.B) { + n := 100_000 pageRank := New() - rand.Seed(5) - b.ResetTimer() for i := 0; i < b.N; i++ { for from := 0; from < n; from++ { @@ -221,7 +219,7 @@ func BenchmarkOneMillion(b *testing.B) { too := rand.Intn(n) to := too - if too > 800000 { + if too > 80000 { to = rand.Intn(3) }