Ejemplo n.º 1
0
func BenchmarkScan(b *testing.B) {
	// run the Scan b.N times
	for n := 0; n < b.N; n++ {
		file, _ := os.Open("dict.txt")
		graphRes, _, _ := grapher.ScanLinkCompress(file)
		benchGraph = graphRes // to prevent compiler skip
		file.Close()
	}
}
Ejemplo n.º 2
0
func BenchmarkSearch(b *testing.B) {
	// setup
	file, _ := os.Open("dict.txt")
	defer file.Close()
	graphRes, _, _ := grapher.ScanLinkCompress(file)
	benchGraph = graphRes // to prevent compiler skip

	srcNode, _ := graph[6]["bounce"]
	dstNode, _ := graph[6]["lather"]
	src := search.GraphNode(srcNode)
	dst := search.GraphNode(dstNode)
	b.ResetTimer()

	// run the Search b.N times
	for n := 0; n < b.N; n++ {
		_, _, found := search.Path(src, dst)
		benchFound = found // to prevent compiler skip
	}
}
Ejemplo n.º 3
0
func scan(path string) {
	file, err := os.Open(path)
	defer file.Close()
	if err != nil {
		fmt.Println(err)
		return
	}
	var count int
	graph, count, err = grapher.ScanLinkCompress(file)
	if err != nil {
		fmt.Fprintln(os.Stderr, "reading input failed with error:\n", err)
		return
	}
	fmt.Printf("Words scanned: %d\n", count)
	fmt.Printf("Sub-graph count: %d\n", len(graph))
	for k, v := range graph {
		fmt.Printf("Sub-graph[%d] length: %d\n", k, len(v))
	}
	if count < 100 {
		//not suitable for large graphs:
		fmt.Println("FULL GRAPH: ", graph)
	}
	fmt.Printf("\n")
}