Skip to content

Commit

Permalink
Update benchmark and helper func
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Dec 24, 2023
1 parent db5631c commit 32a14b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 20 additions & 1 deletion pagerank.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package pagerank

import "math"
import (
"fmt"
"math"
)

type Interface interface {
Rank(followingProb, tolerance float64, resultFunc func(label int, rank float64))
Expand All @@ -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]

Expand Down
8 changes: 3 additions & 5 deletions pagerank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,19 @@ 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++ {
for j := 0; j < rand.Intn(400); j++ {
too := rand.Intn(n)

to := too
if too > 800000 {
if too > 80000 {
to = rand.Intn(3)
}

Expand Down

0 comments on commit 32a14b9

Please sign in to comment.