diff options
author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2020-01-23 12:16:30 +0900 |
---|---|---|
committer | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2020-01-23 12:16:30 +0900 |
commit | 670b6a9aa93ca98e45c15ddd1a4590aabc4a635b (patch) | |
tree | 9609dbc331edc0ee6c9f05faf82fe3d075c4aa2c /template/go | |
parent | fbb650c33bd1dd791cc2e79b5b034301b7abbbe3 (diff) | |
download | vim-sonictemplate-670b6a9aa93ca98e45c15ddd1a4590aabc4a635b.tar.gz vim-sonictemplate-670b6a9aa93ca98e45c15ddd1a4590aabc4a635b.tar.bz2 vim-sonictemplate-670b6a9aa93ca98e45c15ddd1a4590aabc4a635b.zip |
Add some templates
Diffstat (limited to 'template/go')
-rw-r--r-- | template/go/base-test-bench.go | 13 | ||||
-rw-r--r-- | template/go/snip-abs.go | 6 | ||||
-rw-r--r-- | template/go/snip-benchmark-case.go | 5 | ||||
-rw-r--r-- | template/go/snip-max-slice.go | 9 | ||||
-rw-r--r-- | template/go/snip-max-two.go | 6 | ||||
-rw-r--r-- | template/go/snip-min-slice.go | 9 | ||||
-rw-r--r-- | template/go/snip-min-two.go | 6 |
7 files changed, 54 insertions, 0 deletions
diff --git a/template/go/base-test-bench.go b/template/go/base-test-bench.go new file mode 100644 index 0000000..0960dc8 --- /dev/null +++ b/template/go/base-test-bench.go @@ -0,0 +1,13 @@ +package {{_expr_:substitute('{{_name_}}', '_test', '', '')}} + +import ( + "testing" +) + +func BenchmarkSimple(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + {{_cursor_}} + } +} +{{_filter_:benchmark}} diff --git a/template/go/snip-abs.go b/template/go/snip-abs.go new file mode 100644 index 0000000..63f75a2 --- /dev/null +++ b/template/go/snip-abs.go @@ -0,0 +1,6 @@ +func abs(v {{_input_:type}}) {{_input_:type}} { + if v < 0 { + return -v + } + return v +} diff --git a/template/go/snip-benchmark-case.go b/template/go/snip-benchmark-case.go new file mode 100644 index 0000000..da08f29 --- /dev/null +++ b/template/go/snip-benchmark-case.go @@ -0,0 +1,5 @@ +func Benchmark{{_cursor_}}(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + } +} diff --git a/template/go/snip-max-slice.go b/template/go/snip-max-slice.go new file mode 100644 index 0000000..4a022ba --- /dev/null +++ b/template/go/snip-max-slice.go @@ -0,0 +1,9 @@ +func max(a []{{_input_:type}}) {{_input_:type}} { + m := a[0] + for _, v := range a { + if v > m { + m = v + } + } + return m +} diff --git a/template/go/snip-max-two.go b/template/go/snip-max-two.go new file mode 100644 index 0000000..3fc716c --- /dev/null +++ b/template/go/snip-max-two.go @@ -0,0 +1,6 @@ +func max(a, b {{_input_:type}}) {{_input_:type}} { + if a > b { + return a + } + return b +} diff --git a/template/go/snip-min-slice.go b/template/go/snip-min-slice.go new file mode 100644 index 0000000..733bcdc --- /dev/null +++ b/template/go/snip-min-slice.go @@ -0,0 +1,9 @@ +func min(a []{{_input_:type}}) {{_input_:type}} { + m := a[0] + for _, v := range a { + if v < m { + m = v + } + } + return m +} diff --git a/template/go/snip-min-two.go b/template/go/snip-min-two.go new file mode 100644 index 0000000..29f8d48 --- /dev/null +++ b/template/go/snip-min-two.go @@ -0,0 +1,6 @@ +func min(a, b {{_input_:type}}) {{_input_:type}} { + if a < b { + return a + } + return b +} |