Skip to content

feat: add support for benchmarks (#144)#144

Draft
tkrop wants to merge 1 commit into
mainfrom
benchmark
Draft

feat: add support for benchmarks (#144)#144
tkrop wants to merge 1 commit into
mainfrom
benchmark

Conversation

@tkrop
Copy link
Copy Markdown
Owner

@tkrop tkrop commented May 11, 2026

Description

This pull request generalizes the test.Factory[P] to allow arbitrary test interfaces while adding support for *testing.B using a wrapper that is created by test.Benchmark(b). This allows to create parameterized benchmarks using a consistent pattern to regular parameterized tests as follows:

func BenchmarkUnit(b *testing.B) {
    test.Map(test.Benchmark(b), unitTestCases).
        // Exclude of test cases temporary or permanent.
        Filter(test.Not(test.Pattern[T]("^test-case-prefix"))).
        // Include of test cases temporary or permanent.
        Filter(test.Pattern[T]("^test-case-name$")).
        // Execute benchmark setup and loop phases.
        Benchmark(func(b *testing.B, param UnitParams) func(b *testing.B) {
            // Setup
            unit := NewUnitService(param.input*...)

            // Define processed bytes.
            b.SetBytes(len(param.input*))

            // Loop
            return func(b *testing.B) {
                result, err := unit.call(param.input*...)

                // Prevent optimization.
                runtime.KeepAlive(result)
                runtime.KeepAlive(err)
            }
        })
}

The pull request also makes intensive updates and improvements on the documentation, improves test to ensure functionality, and fixes a small bug in the pattern tests.

Besides, the pull request also updates dependencies to the latest minor versions.

Related Issue(s)

fixes #144.

Testing

Run make test, since the code is highly unit tested.

Checklist

  • I have reviewed and tested the changes thoroughly.
  • I have added appropriate documentation to the code for clarity.
  • I have communicated the consequences of the updates to customers.

Signed-off-by: Tronje Krop tronje.krop@jactors.de

@tkrop tkrop self-assigned this May 11, 2026
tkrop added a commit that referenced this pull request May 12, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 12, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 12, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 12, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 13, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 13, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 14, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 14, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 14, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 14, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 14, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 14, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
tkrop added a commit that referenced this pull request May 14, 2026
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
Signed-off-by: Tronje Krop <tronje.krop@jactors.de>
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

Successfully merging this pull request may close these issues.

1 participant