@@ -83,6 +83,11 @@ func init() {
83
83
}
84
84
85
85
JetTestingSet .AddGlobal ("dummy" , dummy )
86
+ JetTestingSet .AddGlobalFunc ("customFn" , func (args Arguments ) reflect.Value {
87
+ args .RequireNumOfArguments ("customFn" , 1 , 1 )
88
+ return args .Get (0 )
89
+ })
90
+
86
91
JetTestingLoader .Set ("actionNode_dummy" , `hello {{dummy("WORLD")}}` )
87
92
JetTestingLoader .Set ("noAllocFn" , `hello {{ "José" }} {{1}} {{ "José" }}` )
88
93
JetTestingLoader .Set ("rangeOverUsers" , `{{range .}}{{.Name}}-{{.Email}}{{end}}` )
@@ -91,6 +96,8 @@ func init() {
91
96
JetTestingLoader .Set ("BenchCustomRanger" , "{{range .}}{{.Name}}{{end}}" )
92
97
JetTestingLoader .Set ("BenchIntsRanger" , "{{range ints(0, .)}} {{end}}" )
93
98
JetTestingLoader .Set ("BenchCustomRender" , "{{range k, v := ints(0, .N)}}{{.Field}}{{end}}" )
99
+ JetTestingLoader .Set ("BenchCallCustomFn" , "{{range ints(0, .N)}}{{customFn(.)}}{{end}}" )
100
+ JetTestingLoader .Set ("BenchExecPipeline" , "{{range ints(0, .N)}}{{. | customFn}}{{end}}" )
94
101
}
95
102
96
103
func RunJetTest (t * testing.T , variables VarMap , context interface {}, testName , testContent , testExpected string ) {
@@ -970,6 +977,32 @@ func BenchmarkCustomRender(b *testing.B) {
970
977
}
971
978
}
972
979
980
+ // BenchmarkCallCustomFn benchmarks executing a template that calls a custom
981
+ // function repeatedly.
982
+ func BenchmarkCallCustomFn (b * testing.B ) {
983
+ t , _ := JetTestingSet .GetTemplate ("BenchCallCustomFn" )
984
+ execCtx := struct { N int }{N : b .N }
985
+ b .ResetTimer ()
986
+ err := t .Execute (ww , nil , execCtx )
987
+ if err != nil {
988
+ b .Error (err .Error ())
989
+ }
990
+
991
+ }
992
+
993
+ // BenchmarkExecPipeline benchmarks executing a template that calls a pipeline
994
+ // repeatedly.
995
+ func BenchmarkExecPipeline (b * testing.B ) {
996
+ t , _ := JetTestingSet .GetTemplate ("BenchExecPipeline" )
997
+ execCtx := struct { N int }{N : b .N }
998
+ b .ResetTimer ()
999
+ err := t .Execute (ww , nil , execCtx )
1000
+ if err != nil {
1001
+ b .Error (err .Error ())
1002
+ }
1003
+
1004
+ }
1005
+
973
1006
// BenchmarkFieldAccess benchmarks executing a template that accesses fields
974
1007
// in the current context.
975
1008
//
0 commit comments