Fumitoshi Ukai | cc8d0cd | 2015-06-19 10:17:48 +0900 | [diff] [blame] | 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 | |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 15 | package kati |
Fumitoshi Ukai | cc8d0cd | 2015-06-19 10:17:48 +0900 | [diff] [blame] | 16 | |
Fumitoshi Ukai | b44b12d | 2015-07-07 14:19:32 +0900 | [diff] [blame^] | 17 | import "testing" |
Fumitoshi Ukai | cc8d0cd | 2015-06-19 10:17:48 +0900 | [diff] [blame] | 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 | } |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 28 | ev := NewEvaluator(make(map[string]Var)) |
Fumitoshi Ukai | b44b12d | 2015-07-07 14:19:32 +0900 | [diff] [blame^] | 29 | var buf buffer |
Fumitoshi Ukai | a44b766 | 2015-06-19 11:07:07 +0900 | [diff] [blame] | 30 | b.ReportAllocs() |
| 31 | b.ResetTimer() |
Fumitoshi Ukai | cc8d0cd | 2015-06-19 10:17:48 +0900 | [diff] [blame] | 32 | for i := 0; i < b.N; i++ { |
| 33 | buf.Reset() |
| 34 | strip.Eval(&buf, ev) |
| 35 | } |
| 36 | } |
Fumitoshi Ukai | ce14acb | 2015-06-19 13:54:53 +0900 | [diff] [blame] | 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 | } |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 47 | ev := NewEvaluator(make(map[string]Var)) |
Fumitoshi Ukai | b44b12d | 2015-07-07 14:19:32 +0900 | [diff] [blame^] | 48 | var buf buffer |
Fumitoshi Ukai | ce14acb | 2015-06-19 13:54:53 +0900 | [diff] [blame] | 49 | b.ReportAllocs() |
| 50 | b.ResetTimer() |
| 51 | for i := 0; i < b.N; i++ { |
| 52 | buf.Reset() |
| 53 | sort.Eval(&buf, ev) |
| 54 | } |
| 55 | } |
Fumitoshi Ukai | 77411fb | 2015-06-19 15:46:21 +0900 | [diff] [blame] | 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 | } |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 68 | ev := NewEvaluator(make(map[string]Var)) |
Fumitoshi Ukai | b44b12d | 2015-07-07 14:19:32 +0900 | [diff] [blame^] | 69 | var buf buffer |
Fumitoshi Ukai | 77411fb | 2015-06-19 15:46:21 +0900 | [diff] [blame] | 70 | b.ReportAllocs() |
| 71 | b.ResetTimer() |
| 72 | for i := 0; i < b.N; i++ { |
| 73 | buf.Reset() |
| 74 | patsubst.Eval(&buf, ev) |
| 75 | } |
| 76 | } |