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

time: microoptimise the Time formating methods (use custom number->string conversion, instead of string interpolation) #20917

Merged
merged 26 commits into from Feb 28, 2024

Conversation

enghitalo
Copy link
Contributor

@enghitalo enghitalo commented Feb 27, 2024

  • no breaking changes, no new features
import time
import benchmark

const max_iterations = 100_000

fn main() {
	mut b := benchmark.start()

	for i := 0; i < max_iterations; i++ {
		time.utc().format_rfc3339()
	}

	b.measure("time.utc().format_rfc3339()")

	for i := 0; i < max_iterations; i++ {
		time.now().format_rfc3339() 
	}

	b.measure("time.now().format_rfc3339()")
}

Before

╰─ v -prod crun b.v ─╯
 SPENT    23.206 ms in time.utc().format_rfc3339()
 SPENT    42.505 ms in time.now().format_rfc3339()

After

╰─ v -prod crun b.v ─╯
 SPENT     6.150 ms in time.utc().format_rfc3339()
 SPENT    37.007 ms in time.now().format_rfc3339()

vlib/time/format.v Outdated Show resolved Hide resolved
vlib/time/format.v Outdated Show resolved Hide resolved
vlib/time/format.v Outdated Show resolved Hide resolved
vlib/time/format.v Outdated Show resolved Hide resolved
vlib/time/time_test.v Outdated Show resolved Hide resolved
@spytheman spytheman changed the title Perf/time formating time: microoptimise the Time formating methods (use custom number->string conversion, instead of string interpolation) Feb 27, 2024
Copy link
Member

@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 d5370bd into vlang:master Feb 28, 2024
48 checks passed
raw-bin pushed a commit to raw-bin/v that referenced this pull request Mar 9, 2024
raw-bin pushed a commit to raw-bin/v that referenced this pull request Mar 9, 2024
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.

None yet

2 participants