Esempio 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()
}
Esempio 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)
}
Esempio n. 3
0
func timeTrial(n int) float64 {
	const MAX = 1000000
	a := make([]int, n)
	r := rand.New(0)

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

	timer := stopwatch.New()
	_ = threesum.CountD(a)
	return timer.ElapsedTime()
}
Esempio n. 4
0
func time(alg string, a []float64) float64 {
	data := sort.Float64Slice(a)
	timer := stopwatch.New()

	switch alg {
	case "Gosort":
		gosort.Sort(data)
	case "Insertion":
		insertion.Sort(data)
	case "Selection":
		selection.Sort(data)
	case "Shell":
		shell.Sort(data)
	default:
		panic("Unrecognized Algorithm")
	}

	return timer.ElapsedTime()
}
Esempio n. 5
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)
}