Skip to content

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

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

perf: string.starts_with and string.ends_with by 10x in TCC#22620
spytheman merged 2 commits intovlang:masterfrom
enghitalo:perf/starts_with

Conversation

@enghitalo
Copy link
Copy Markdown
Contributor

@enghitalo enghitalo commented Oct 22, 2024

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
Copy link
Copy Markdown
Contributor

@spytheman spytheman left a comment

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