Home | History | Annotate | Download | only in kati
      1 // Copyright 2015 Google Inc. All rights reserved
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //      http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 package kati
     16 
     17 import "testing"
     18 
     19 func BenchmarkFuncStrip(b *testing.B) {
     20 	strip := &funcStrip{
     21 		fclosure: fclosure{
     22 			args: []Value{
     23 				literal("(strip"),
     24 				literal("a b  c "),
     25 			},
     26 		},
     27 	}
     28 	ev := NewEvaluator(make(map[string]Var))
     29 	var buf evalBuffer
     30 	b.ReportAllocs()
     31 	b.ResetTimer()
     32 	for i := 0; i < b.N; i++ {
     33 		buf.Reset()
     34 		strip.Eval(&buf, ev)
     35 	}
     36 }
     37 
     38 func BenchmarkFuncSort(b *testing.B) {
     39 	sort := &funcSort{
     40 		fclosure: fclosure{
     41 			args: []Value{
     42 				literal("(sort"),
     43 				literal("foo bar lose"),
     44 			},
     45 		},
     46 	}
     47 	ev := NewEvaluator(make(map[string]Var))
     48 	var buf evalBuffer
     49 	b.ReportAllocs()
     50 	b.ResetTimer()
     51 	for i := 0; i < b.N; i++ {
     52 		buf.Reset()
     53 		sort.Eval(&buf, ev)
     54 	}
     55 }
     56 
     57 func BenchmarkFuncPatsubst(b *testing.B) {
     58 	patsubst := &funcPatsubst{
     59 		fclosure: fclosure{
     60 			args: []Value{
     61 				literal("(patsubst"),
     62 				literal("%.java"),
     63 				literal("%.class"),
     64 				literal("foo.jar bar.java baz.h"),
     65 			},
     66 		},
     67 	}
     68 	ev := NewEvaluator(make(map[string]Var))
     69 	var buf evalBuffer
     70 	b.ReportAllocs()
     71 	b.ResetTimer()
     72 	for i := 0; i < b.N; i++ {
     73 		buf.Reset()
     74 		patsubst.Eval(&buf, ev)
     75 	}
     76 }
     77