2019-10-26 17:20:36 +02:00
|
|
|
import encoding.base64
|
|
|
|
|
2021-02-21 16:05:03 +01:00
|
|
|
fn test_long_encoding() {
|
2019-10-26 17:20:36 +02:00
|
|
|
repeats := 1000
|
|
|
|
input_size := 3000
|
2019-12-07 13:13:23 +01:00
|
|
|
|
2021-02-26 07:22:12 +01:00
|
|
|
s_original := []byte{len: input_size, init: `a`}
|
2019-10-26 17:20:36 +02:00
|
|
|
s_encoded := base64.encode(s_original)
|
|
|
|
s_decoded := base64.decode(s_encoded)
|
2019-12-07 13:13:23 +01:00
|
|
|
|
2019-10-26 17:20:36 +02:00
|
|
|
assert s_encoded.len > s_original.len
|
|
|
|
assert s_original == s_decoded
|
|
|
|
|
|
|
|
mut s := 0
|
2019-12-07 13:13:23 +01:00
|
|
|
|
2021-02-21 16:05:03 +01:00
|
|
|
ebuffer := unsafe { malloc(s_encoded.len) }
|
|
|
|
for _ in 0 .. repeats {
|
2019-12-07 13:13:23 +01:00
|
|
|
resultsize := base64.encode_in_buffer(s_original, ebuffer)
|
2019-10-26 17:20:36 +02:00
|
|
|
s += resultsize
|
|
|
|
assert resultsize == s_encoded.len
|
|
|
|
}
|
|
|
|
|
2021-02-21 16:05:03 +01:00
|
|
|
dbuffer := unsafe { malloc(s_decoded.len) }
|
|
|
|
for _ in 0 .. repeats {
|
2019-12-07 13:13:23 +01:00
|
|
|
resultsize := base64.decode_in_buffer(s_encoded, dbuffer)
|
2019-10-26 17:20:36 +02:00
|
|
|
s += resultsize
|
|
|
|
assert resultsize == s_decoded.len
|
|
|
|
}
|
|
|
|
|
2021-02-21 16:05:03 +01:00
|
|
|
println('Final s: $s')
|
2019-10-26 17:20:36 +02:00
|
|
|
// assert s == 39147008
|
|
|
|
}
|