nickva commented on issue #5801:
URL: https://github.com/apache/couchdb/issues/5801#issuecomment-3603995769
A good idea to investigate @Benjamin-Philip
With the built-in script I still see that the nif is faster even with the
jit. Without the jit it's even more pronounced. Maybe we could do a length
limit, if it's < 100 bytes we use the built-ins, otherwise use the nif? Pretty
sure there is a way to check if we're running a jitted emulator build too.
I patched the built-in script like this:
```
--- i/src/b64url/test/benchmark.escript
+++ w/src/b64url/test/benchmark.escript
@@ -116,25 +116,18 @@ run_worker(St, Started) ->
do_round_trip(St) ->
Size = St#st.minsize + rand:uniform(St#st.maxsize - St#st.minsize),
- Data = crypto:strong_rand_bytes(Size),
+ Data = rand:bytes(Size),
Encoded = (St#st.module):encode(Data),
Data = (St#st.module):decode(Encoded),
St#st{total_bytes=St#st.total_bytes+Size}.
encode(Url) ->
- Url1 = iolist_to_binary(re:replace(base64:encode(Url), "=+$", "")),
- Url2 = iolist_to_binary(re:replace(Url1, "/", "_", [global])),
- iolist_to_binary(re:replace(Url2, "\\+", "-", [global])).
+ base64:encode(Url, #{mode => urlsafe, padding => false}).
decode(Url64) ->
- Url1 = re:replace(iolist_to_binary(Url64), "-", "+", [global]),
- Url2 = iolist_to_binary(
- re:replace(iolist_to_binary(Url1), "_", "/", [global])
- ),
- Padding = list_to_binary(lists:duplicate((4 - size(Url2) rem 4) rem 4,
$=)),
- base64:decode(<<Url2/binary, Padding/binary>>).
+ base64:decode(Url64, #{mode => urlsafe, padding => false}).
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]