mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
base64: some optimizations
* Add a test for the base64 encoding/decoding of long strings (i.e. mainly memory allocation). * Make vlib/encoding/base64/base64_memory_test.v resemble more test.v from https://github.com/kostya/benchmarks . * base64: some optimizations, also add base64.encode_in_buffer and base64.decode_in_buffer . * Fix tests passing static strings. * Reduce time needed for base64_memory_test.v . * Optimize encoding.base64.Index access too (it is static), which speeds up decoding.
This commit is contained in:
parent
272b0aec82
commit
2d05c906d5
3 changed files with 120 additions and 36 deletions
32
vlib/encoding/base64/base64_memory_test.v
Normal file
32
vlib/encoding/base64/base64_memory_test.v
Normal file
|
@ -0,0 +1,32 @@
|
|||
import encoding.base64
|
||||
|
||||
fn test_long_encoding(){
|
||||
repeats := 1000
|
||||
input_size := 3000
|
||||
|
||||
s_original := 'a'.repeat(input_size)
|
||||
s_encoded := base64.encode(s_original)
|
||||
s_decoded := base64.decode(s_encoded)
|
||||
|
||||
assert s_encoded.len > s_original.len
|
||||
assert s_original == s_decoded
|
||||
|
||||
mut s := 0
|
||||
|
||||
ebuffer := malloc( s_encoded.len )
|
||||
for i := 0; i < repeats; i++ {
|
||||
resultsize := base64.encode_in_buffer(s_original, mut ebuffer)
|
||||
s += resultsize
|
||||
assert resultsize == s_encoded.len
|
||||
}
|
||||
|
||||
dbuffer := malloc( s_decoded.len )
|
||||
for i := 0; i < repeats; i++ {
|
||||
resultsize := base64.decode_in_buffer(s_encoded, mut dbuffer)
|
||||
s += resultsize
|
||||
assert resultsize == s_decoded.len
|
||||
}
|
||||
|
||||
println( 'Final s: $s' )
|
||||
// assert s == 39147008
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue