Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't reproduce benchmark results #162

Open
vitalyisaev2 opened this issue Jul 3, 2024 · 0 comments
Open

Can't reproduce benchmark results #162

vitalyisaev2 opened this issue Jul 3, 2024 · 0 comments

Comments

@vitalyisaev2
Copy link

Seems like Go standard library was fixed since this library was introduced, so now time.Parse beats datetime.ParseAny:

package bench

import (
	"testing"
	"time"

	"github.com/araddon/dateparse"
	"github.com/stretchr/testify/require"
)

func TestDateEquivalence(t *testing.T) {
	format := "2006-01-02"
	input := "1988-11-20"

	out1, err := time.Parse(format, input)
	require.NotNil(t, out1)
	require.NoError(t, err)

	out2, err := dateparse.ParseAny(input)
	require.NotNil(t, out2)
	require.NoError(t, err)

	require.True(t, out1.Equal(out2))
}

func TestTimeEquivalence(t *testing.T) {
	format := "2006-01-02 15:04:05.999999"
	input := "1988-11-20 11:12:13.444444"

	out1, err := time.Parse(format, input)
	require.NotNil(t, out1)
	require.NoError(t, err)

	out2, err := dateparse.ParseAny(input)
	require.NotNil(t, out2)
	require.NoError(t, err)

	require.True(t, out1.Equal(out2))
}

func BenchmarkDateParseStdLib(b *testing.B) {
	format := "2006-01-02"
	input := "1988-11-20"
	for i := 0; i < b.N; i++ {
		out, err := time.Parse(format, input)
		require.NotNil(b, out)
		require.NoError(b, err)
	}
}

func BenchmarkDateParseAraddonDateparse(b *testing.B) {
	input := "1988-11-20"
	for i := 0; i < b.N; i++ {
		out, err := dateparse.ParseStrict(input)
		require.NotNil(b, out)
		require.NoError(b, err)
	}
}

func BenchmarkTimeParseStdLib(b *testing.B) {
	format := "2006-01-02 15:04:05.999999"
	input := "1988-11-20 11:12:13.444444"
	for i := 0; i < b.N; i++ {
		out, err := time.Parse(format, input)
		require.NotNil(b, out)
		require.NoError(b, err)
	}
}

func BenchmarkTimeParseAraddonTimeparse(b *testing.B) {
	input := "1988-11-20 11:12:13.444444"
	for i := 0; i < b.N; i++ {
		out, err := dateparse.ParseAny(input)
		require.NotNil(b, out)
		require.NoError(b, err)
	}
}

Results:

cpu: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
BenchmarkDateParseStdLib
BenchmarkDateParseStdLib-16                      2813982               417.9 ns/op
BenchmarkDateParseAraddonDateparse
BenchmarkDateParseAraddonDateparse-16            2003248               575.2 ns/op
BenchmarkTimeParseStdLib
BenchmarkTimeParseStdLib-16                      2293155               520.0 ns/op
BenchmarkTimeParseAraddonTimeparse
BenchmarkTimeParseAraddonTimeparse-16            1585695               749.0 ns/op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant