diff ai_test.go @ 0:43e580fa4719

first commit.
author pyon@macmini
date Mon, 04 Sep 2017 21:40:33 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ai_test.go	Mon Sep 04 21:40:33 2017 +0900
@@ -0,0 +1,76 @@
+package main
+
+// $ go test -bench=.
+/*
+void cint_bench( int n ) {
+    int x = 1;
+    for( i:=0; i < n; i++ ){
+        x += x * 1 + x * 1;
+        x -= x * 1 + x * 1;
+    }
+}
+
+void cfloat_bench( int n ) {
+    float x = 1.0;
+    for( i:=0; i < n; i++ ){
+        x += x * 1.0 + x * 1.0;
+        x -= x * 1.0 + x * 1.0;
+    }
+}
+import "C"
+*/
+
+import (
+    //"container/list"
+    "fmt"
+    "math/rand"
+    "sort"
+    "testing"
+)
+
+func BenchmarkIntBench( b *testing.B ) {
+    x := 1;
+    for i:=0; i < b.N; i++ {
+        x += x * 1 + x * 1
+        x -= x * 1 + x * 1
+    }
+    //fmt.Println( x )
+}
+
+func BenchmarkFloatBench( b *testing.B ) {
+    x := 1.0;
+    for i:=0; i < b.N; i++ {
+        x += x * 1.0 + x * 1.0
+        x -= x * 1.0 + x * 1.0
+    }
+    //fmt.Println( x )
+}
+
+/*
+func BenchmarkCIntBench( b *testing.B ) {
+    C.cint_bench( b.N )
+}
+
+func BenchmarkCFloatBench( b *testing.B ) {
+    C.cfloat_bench( b.N )
+}
+*/
+
+func TestX( t *testing.T ) {
+    for i:=0; i < 20; i++ {
+        fmt.Println( rand.Intn( 3 ) - 1 )
+    }
+}
+
+// $ go test -run="S1"
+func TestS1( t *testing.T ) {
+    type Idx struct {
+        index int
+        value int
+    }
+    god7 := []Idx{ { 0,6 }, { 1,1 }, { 2,3 }, { 3,2 }, { 4,4 }, { 5,0 }, { 6,6 } }
+    sort.SliceStable( god7, func( i, j int ) bool { return god7[i].value < god7[j].value } )
+    fmt.Println( god7 )
+}
+
+