Skip to content

perf: string.starts_with and string.ends_with by 10x in TCC - #22620

Merged
spytheman merged 2 commits into
vlang:masterfrom
enghitalo:perf/starts_with
Oct 22, 2024
Merged

spytheman merged 2 commits into
vlang:masterfrom
enghitalo:perf/starts_with

Conversation

@enghitalo

@enghitalo enghitalo commented Oct 22, 2024 •

Copy link
Copy Markdown
Contributor

10x faster in TCC
image

import benchmark

const max_iterations = 1_000_000

fn main() {
	value := 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
	mut b := benchmark.start()
	for i := 0; i < max_iterations; i++ {
		value.starts_with('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz')
		// value.ends_with('pqrstuvwxyzabcdefghijklmnopqrstuvwxyz')
	}
	b.measure("value.starts_with('abcd')")
}

Huly®: V_0.6-21069

@enghitalo enghitalo changed the title perf: string.starts_with perf: string.starts_with and string.ends_with by 10x in TCC Oct 22, 2024

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman
spytheman merged commit b5795dc into vlang:master Oct 22, 2024
@felipensp

Copy link
Copy Markdown
Member

Nice catch. 💯

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.

3 participants