Closed
Conversation
ruslandoga
commented
Jul 23, 2025
| end, | ||
| "custom multipart encode" => fn input -> | ||
| DBConnection.Query.Ch.Query.custom_multipart_encode(input.query, input.params, input.opts) | ||
| end |
Collaborator
Author
There was a problem hiding this comment.
Results
$ env MIX_ENV=bench mix run bench/query.exs
Operating System: macOS
CPU Information: Apple M2
Number of Available Cores: 8
Available memory: 8 GB
Elixir 1.18.4
Erlang 28.0.1
JIT enabled: true
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 0 ns
reduction time: 0 ns
parallel: 1
inputs: 0 params, 1 named param, 10 named params, 10 positional params, 100 positional params
Estimated total run time: 1 min 45 s
Benchmarking custom multipart encode with input 0 params ...
Benchmarking custom multipart encode with input 1 named param ...
Benchmarking custom multipart encode with input 10 named params ...
Benchmarking custom multipart encode with input 10 positional params ...
Benchmarking custom multipart encode with input 100 positional params ...
Benchmarking multipart encode with input 0 params ...
Benchmarking multipart encode with input 1 named param ...
Benchmarking multipart encode with input 10 named params ...
Benchmarking multipart encode with input 10 positional params ...
Benchmarking multipart encode with input 100 positional params ...
Benchmarking query string encode with input 0 params ...
Benchmarking query string encode with input 1 named param ...
Benchmarking query string encode with input 10 named params ...
Benchmarking query string encode with input 10 positional params ...
Benchmarking query string encode with input 100 positional params ...
Calculating statistics...
Formatting results...
##### With input 0 params #####
Name ips average deviation median 99th %
query string encode 11.23 M 89.07 ns ±42180.35% 42 ns 84 ns
custom multipart encode 1.59 M 627.63 ns ±3688.39% 500 ns 916 ns
multipart encode 0.48 M 2076.18 ns ±729.98% 1625 ns 3792 ns
Comparison:
query string encode 11.23 M
custom multipart encode 1.59 M - 7.05x slower +538.55 ns
multipart encode 0.48 M - 23.31x slower +1987.11 ns
##### With input 1 named param #####
Name ips average deviation median 99th %
query string encode 6.02 M 166.10 ns ±18451.53% 125 ns 250 ns
custom multipart encode 1.40 M 715.88 ns ±2991.42% 583 ns 792 ns
multipart encode 0.33 M 3041.13 ns ±475.63% 2418 ns 5709 ns
Comparison:
query string encode 6.02 M
custom multipart encode 1.40 M - 4.31x slower +549.77 ns
multipart encode 0.33 M - 18.31x slower +2875.02 ns
##### With input 10 named params #####
Name ips average deviation median 99th %
query string encode 1900.51 K 0.53 μs ±4765.09% 0.46 μs 0.67 μs
custom multipart encode 454.49 K 2.20 μs ±462.59% 1.75 μs 4.58 μs
multipart encode 82.65 K 12.10 μs ±38.17% 11.33 μs 33.46 μs
Comparison:
query string encode 1900.51 K
custom multipart encode 454.49 K - 4.18x slower +1.67 μs
multipart encode 82.65 K - 22.99x slower +11.57 μs
##### With input 10 positional params #####
Name ips average deviation median 99th %
query string encode 1364.13 K 0.73 μs ±2293.63% 0.71 μs 0.96 μs
custom multipart encode 962.79 K 1.04 μs ±1354.36% 0.88 μs 1.38 μs
multipart encode 86.87 K 11.51 μs ±59.70% 10 μs 37.06 μs
Comparison:
query string encode 1364.13 K
custom multipart encode 962.79 K - 1.42x slower +0.31 μs
multipart encode 86.87 K - 15.70x slower +10.78 μs
##### With input 100 positional params #####
Name ips average deviation median 99th %
custom multipart encode 207.53 K 4.82 μs ±120.68% 4.33 μs 9.63 μs
query string encode 132.51 K 7.55 μs ±404.52% 7.25 μs 10.42 μs
multipart encode 8.45 K 118.36 μs ±19.60% 113.04 μs 203.48 μs
Comparison:
custom multipart encode 207.53 K
query string encode 132.51 K - 1.57x slower +2.73 μs
multipart encode 8.45 K - 24.56x slower +113.54 μs
hawkyre
reviewed
Jul 23, 2025
| end | ||
|
|
||
| defp multipart_params(params, boundary) when is_map(params) do | ||
| multipart_named_params(Map.to_list(params), boundary, []) |
Contributor
There was a problem hiding this comment.
make acc default to [] ? cleaner implementation imo
Contributor
|
This looks great, what are the benchmarks saying? Is the custom impl faster? |
Collaborator
Author
|
Yes, the custom impl seems to be a bit faster. |
Collaborator
Author
|
Closing in favor of #259 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ideas for #259