func main() { __b1 = pattern.NewBinding() ROUNDS := 1000000 if len(os.Args) > 1 { ROUNDS, _ = strconv.Atoi(os.Args[1]) } bench(NewMul(NewConst(5), NewConst(1)), ROUNDS) bench(NewMul(NewConst(1), NewConst(10)), ROUNDS) bench(NewMul(NewConst(20), NewConst(20)), ROUNDS) }
func main() { input := NewMul(NewConst(1), NewConst(20)) fmt.Printf("%s\n", input) __b1 := pattern. NewBinding() switch { case pattern.Match(input, &pattern.Node{ reflect.TypeOf(&Mul{}), -1, nil, []*pattern.Node{&pattern. Node{reflect.TypeOf(&Const{}), -1, nil, []*pattern.Node{&pattern. Node{nil, -1, 10, nil}}}, &pattern.Node{reflect.TypeOf(&Const{}), -1, nil, []*pattern.Node{&pattern.Node{nil, -1, 20, nil}}}}}, __b1): fmt.Printf("matched\n") case pattern.Match(input, &pattern.Node{ reflect.TypeOf(&Mul{}), -1, nil, []*pattern.Node{&pattern. Node{reflect.TypeOf(&Const{}), -1, nil, []*pattern.Node{&pattern. Node{nil, 0, nil, nil}}}, &pattern.Node{nil, 1, nil, nil}, }}, __b1): x := __b1.Data[0].(int) y := __b1.Data[1].(Expr) fmt.Printf("matched x=%v, y=%v\n", x, y) } }