-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
time: implement faster and simpler push_http_header
#26155
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
Conversation
Benchmark Sourcemodule main
import time
import benchmark
const time_to_test = time.Time{
year: 1980
month: 7
day: 11
hour: 21
minute: 23
second: 42
}
fn main() {
println('Testing time formatting performance...')
mut http1_1_buffer1 := 'HTTP/1.1 200 OK\r\nDate: '.bytes()
mut http1_1_buffer2 := 'HTTP/1.1 200 OK\r\nDate: '.bytes()
mut b := benchmark.start()
for _ in 0 .. 1_000_000 {
a := time_to_test.http_header_string()
unsafe {
http1_1_buffer1.push_many(a.str, a.len)
}
}
b.measure( 'http_header_string 1_000_000 times')
for _ in 0 .. 1_000_000 {
time_to_test.push_to_http_header(mut http1_1_buffer2)
}
b.measure( 'push_to_http_header 1_000_000 times')
} |
push_http_header
|
@spytheman I know that the changes to |
|
@enghitalo it is not a problem - I understand why it is there. |
|
If the target is ES6 or later, something as simple as arr.push(...vals)should work fine. That would be ignoring the If the arr.push(...vals.slice(0, size))(that's what I read on stack overflow, at least...) |
spytheman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, although I would not call it simpler - it can be more performant, since it avoids allocating a new dynamic array inside push_to_http_header .
push_http_headerpush_http_header
No description provided.