Closed AdamCooman closed 3 weeks ago
To allow talking about performance, I created a bunch of benchmarks and ran these. The benchmarking repository can be found here: https://github.com/AdamCooman/yaml_benchmarking
When I compare using the latest version of the yaml code (https://github.com/AdamCooman/yaml/commit/625261f0bd6a1a6b3e4b22943f72831f871dcc41) versus a version where the dump file is optimized as explained here (https://github.com/AdamCooman/yaml/commit/fad929b5f3b5b6d07bd81fff5370e5b300ba0d5a) I obtain the following speedup:
Hey, thanks for your work! I will incorporate it in a few days
yaml.dump performs num2cell and convertCell on every array. convertCell then uses a for-loop to add each of the elements of the cell array to an ArrayList. This has a lot of overhead, reducing performance when the amount of elements in the array is large. For numeric, logical and string vectors, this is not needed because of two reasons:
Yaml(dumperOptions).dump([1 2 3 4])
just works.There is a caveat for the uints, where Matlab auto-casts them to Integer and Long, while it should be BigInteger as you implemented correctly.
Below, I implemented an alternative version of the
convert
function which tries to avoid the loops as much as possible, but which still passes all tests:I find that the performance of the dump function is better when using this convert function.