blob: b56291efb0f995e18d0ca70811c11a3893ddd741 [file] [log] [blame]
Fumitoshi Ukaicc8d0cd2015-06-19 10:17:48 +09001// 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
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090015package kati
Fumitoshi Ukaicc8d0cd2015-06-19 10:17:48 +090016
Fumitoshi Ukaib44b12d2015-07-07 14:19:32 +090017import "testing"
Fumitoshi Ukaicc8d0cd2015-06-19 10:17:48 +090018
19func BenchmarkFuncStrip(b *testing.B) {
20 strip := &funcStrip{
21 fclosure: fclosure{
22 args: []Value{
23 literal("(strip"),
24 literal("a b c "),
25 },
26 },
27 }
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090028 ev := NewEvaluator(make(map[string]Var))
Fumitoshi Ukaia4a02252015-07-09 14:25:18 +090029 var buf evalBuffer
Fumitoshi Ukaia44b7662015-06-19 11:07:07 +090030 b.ReportAllocs()
31 b.ResetTimer()
Fumitoshi Ukaicc8d0cd2015-06-19 10:17:48 +090032 for i := 0; i < b.N; i++ {
33 buf.Reset()
34 strip.Eval(&buf, ev)
35 }
36}
Fumitoshi Ukaice14acb2015-06-19 13:54:53 +090037
38func BenchmarkFuncSort(b *testing.B) {
39 sort := &funcSort{
40 fclosure: fclosure{
41 args: []Value{
42 literal("(sort"),
43 literal("foo bar lose"),
44 },
45 },
46 }
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090047 ev := NewEvaluator(make(map[string]Var))
Fumitoshi Ukaia4a02252015-07-09 14:25:18 +090048 var buf evalBuffer
Fumitoshi Ukaice14acb2015-06-19 13:54:53 +090049 b.ReportAllocs()
50 b.ResetTimer()
51 for i := 0; i < b.N; i++ {
52 buf.Reset()
53 sort.Eval(&buf, ev)
54 }
55}
Fumitoshi Ukai77411fb2015-06-19 15:46:21 +090056
57func 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 }
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090068 ev := NewEvaluator(make(map[string]Var))
Fumitoshi Ukaia4a02252015-07-09 14:25:18 +090069 var buf evalBuffer
Fumitoshi Ukai77411fb2015-06-19 15:46:21 +090070 b.ReportAllocs()
71 b.ResetTimer()
72 for i := 0; i < b.N; i++ {
73 buf.Reset()
74 patsubst.Eval(&buf, ev)
75 }
76}