Skip to content

Instantly share code, notes, and snippets.

@suminb
Last active May 20, 2019 03:20
Show Gist options
  • Save suminb/83d19147feb92efd50bfc6aa1e7ea1be to your computer and use it in GitHub Desktop.
Save suminb/83d19147feb92efd50bfc6aa1e7ea1be to your computer and use it in GitHub Desktop.
Go sort performance test
package main
import (
"math/rand"
"sort"
"testing"
)
var n = 600000000
var seq = make([]int, n)
func TestRandomSeq(t *testing.T) {
for i := 0; i < n; i++ {
seq[i] = rand.Int()
}
}
func TestSort(t *testing.T) {
sort.Ints(seq)
}
/**
Sorting 600,000,000 random integers
On MacBook Pro (Retina, 15-inch, Mid 2015), 2.8 GHz Intel Core i7, 16 GB 1600 MHz DDR3
$ go test -v sort_test.go
=== RUN TestRandomSeq
--- PASS: TestRandomSeq (13.52s)
=== RUN TestSort
--- PASS: TestSort (164.81s)
PASS
ok command-line-arguments 178.820s
*/
@suminb
Copy link
Author

suminb commented May 20, 2019

Sorting 100,000,000 random integers

$ go test -v sort_test.go
=== RUN   TestRandomSeq
--- PASS: TestRandomSeq (2.21s)
=== RUN   TestSort
--- PASS: TestSort (24.57s)
PASS
ok      command-line-arguments  26.861s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment