Skip to content

Instantly share code, notes, and snippets.

@ayoisaiah
Created October 8, 2020 13:31
Show Gist options
  • Save ayoisaiah/fb2f217590f70a1e6f32003558e7b826 to your computer and use it in GitHub Desktop.
Save ayoisaiah/fb2f217590f70a1e6f32003558e7b826 to your computer and use it in GitHub Desktop.
Benchmarking two unique ways to get a filename without the extension in Go
package main
import (
"testing"
)
var res string
func BenchmarkFileNameWithoutExtSliceNotation(b *testing.B) {
// run the Fib function b.N times
var r string
for n := 0; n < b.N; n++ {
r = fileNameWithoutExtSliceNotation("2020-10-06_19-09.png")
}
res = r
}
func BenchmarkFileNameWithoutExtTrimSuffix(b *testing.B) {
// run the Fib function b.N times
var r string
for n := 0; n < b.N; n++ {
r = fileNameWithoutExtTrimSuffix("2020-10-06_19-09.png")
}
res = r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment