comparison ai_test.go @ 0:43e580fa4719

first commit.
author pyon@macmini
date Mon, 04 Sep 2017 21:40:33 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:43e580fa4719
1 package main
2
3 // $ go test -bench=.
4 /*
5 void cint_bench( int n ) {
6 int x = 1;
7 for( i:=0; i < n; i++ ){
8 x += x * 1 + x * 1;
9 x -= x * 1 + x * 1;
10 }
11 }
12
13 void cfloat_bench( int n ) {
14 float x = 1.0;
15 for( i:=0; i < n; i++ ){
16 x += x * 1.0 + x * 1.0;
17 x -= x * 1.0 + x * 1.0;
18 }
19 }
20 import "C"
21 */
22
23 import (
24 //"container/list"
25 "fmt"
26 "math/rand"
27 "sort"
28 "testing"
29 )
30
31 func BenchmarkIntBench( b *testing.B ) {
32 x := 1;
33 for i:=0; i < b.N; i++ {
34 x += x * 1 + x * 1
35 x -= x * 1 + x * 1
36 }
37 //fmt.Println( x )
38 }
39
40 func BenchmarkFloatBench( b *testing.B ) {
41 x := 1.0;
42 for i:=0; i < b.N; i++ {
43 x += x * 1.0 + x * 1.0
44 x -= x * 1.0 + x * 1.0
45 }
46 //fmt.Println( x )
47 }
48
49 /*
50 func BenchmarkCIntBench( b *testing.B ) {
51 C.cint_bench( b.N )
52 }
53
54 func BenchmarkCFloatBench( b *testing.B ) {
55 C.cfloat_bench( b.N )
56 }
57 */
58
59 func TestX( t *testing.T ) {
60 for i:=0; i < 20; i++ {
61 fmt.Println( rand.Intn( 3 ) - 1 )
62 }
63 }
64
65 // $ go test -run="S1"
66 func TestS1( t *testing.T ) {
67 type Idx struct {
68 index int
69 value int
70 }
71 god7 := []Idx{ { 0,6 }, { 1,1 }, { 2,3 }, { 3,2 }, { 4,4 }, { 5,0 }, { 6,6 } }
72 sort.SliceStable( god7, func( i, j int ) bool { return god7[i].value < god7[j].value } )
73 fmt.Println( god7 )
74 }
75
76