2019-10-26 18:20:36 +03:00
|
|
|
import encoding.base64
|
|
|
|
|
|
|
|
fn test_long_encoding(){
|
|
|
|
repeats := 1000
|
|
|
|
input_size := 3000
|
2019-12-07 15:13:23 +03:00
|
|
|
|
2019-10-26 18:20:36 +03:00
|
|
|
s_original := 'a'.repeat(input_size)
|
|
|
|
s_encoded := base64.encode(s_original)
|
|
|
|
s_decoded := base64.decode(s_encoded)
|
2019-12-07 15:13:23 +03:00
|
|
|
|
2019-10-26 18:20:36 +03:00
|
|
|
assert s_encoded.len > s_original.len
|
|
|
|
assert s_original == s_decoded
|
|
|
|
|
|
|
|
mut s := 0
|
2019-12-07 15:13:23 +03:00
|
|
|
|
2019-10-26 18:20:36 +03:00
|
|
|
ebuffer := malloc( s_encoded.len )
|
|
|
|
for i := 0; i < repeats; i++ {
|
2019-12-07 15:13:23 +03:00
|
|
|
resultsize := base64.encode_in_buffer(s_original, ebuffer)
|
2019-10-26 18:20:36 +03:00
|
|
|
s += resultsize
|
|
|
|
assert resultsize == s_encoded.len
|
|
|
|
}
|
|
|
|
|
|
|
|
dbuffer := malloc( s_decoded.len )
|
|
|
|
for i := 0; i < repeats; i++ {
|
2019-12-07 15:13:23 +03:00
|
|
|
resultsize := base64.decode_in_buffer(s_encoded, dbuffer)
|
2019-10-26 18:20:36 +03:00
|
|
|
s += resultsize
|
|
|
|
assert resultsize == s_decoded.len
|
|
|
|
}
|
|
|
|
|
|
|
|
println( 'Final s: $s' )
|
|
|
|
// assert s == 39147008
|
|
|
|
}
|