view ai_test.go @ 1:c32b619844ba default tip

add eview.go.
author pyon@macmini
date Sun, 17 Sep 2017 14:33:27 +0900
parents 43e580fa4719
children
line wrap: on
line source

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 )
}