time: implement faster and simpler push_http_header#26155
time: implement faster and simpler push_http_header#26155spytheman merged 5 commits intovlang:masterfrom
push_http_header#26155Conversation
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.
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.