Exemplo n.º 1
0
// returns the amount of time (in seconds) to call threesumfast.Count with n random 6-digit integers.
func timeTrial(n int, r *rand.Random) float64 {
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = r.UniformIRange(-MAX, MAX)
	}

	timer := stopwatch.New()
	_ = threesum.Count(a)
	return timer.ElapsedTime()
}
Exemplo n.º 2
0
func main() {
	if len(os.Args) <= 1 {
		fmt.Printf("usage: %s [1Kints|2Kints|4Kints|8Kints].txt\n", filepath.Base(os.Args[0]))
		return
	}

	a, _ := in.ReadAllIntsFromFile(os.Args[1])

	timer := stopwatch.New()
	cnt := threesum.Count(a)
	fmt.Printf("elapsed time: %.2f\n", timer.ElapsedTime())
	fmt.Println(cnt)
}
Exemplo n.º 3
0
func main() {
	if len(os.Args) <= 1 {
		fmt.Printf("usage: %s [1000|2000|4000|8000].txt\n", filepath.Base(os.Args[0]))
		return
	}

	n, _ := strconv.Atoi(os.Args[1])
	a := make([]int, n)
	r := rand.New(0)

	for i := 0; i < n; i++ {
		a[i] = r.UniformIRange(-1000000, 1000000)
	}

	timer := stopwatch.New()
	cnt := threesum.Count(a)
	time := timer.ElapsedTime()
	fmt.Printf("%d triples. %f seconds\n", cnt, time)
}