4 ms·
Fun fact, I wrote my own JSON reader/writer in pure MATLAB, and it is also regex-based, and in many cases, it is faster than MATLAB's own, Mex-based JSON reader
by Derbasti 9y ago
Fun fact, I wrote my own JSON reader/writer in pure MATLAB, and it is also regex-based, and in many cases, it is faster than MATLAB's own, Mex-based JSON reader/writer: https://github.com/bastibe/transplant https://github.com/bastibe/transplant
There are few things as slow as non-vectorized MATLAB code. MATLAB's regex engine is pretty decent, actually, and supports quite a few fancy tricks. For example, I use the regex engine to find the start/end of all numbers and strings ahead of time, and for replacing escape sequences (even unicode escapes!) with their literal characters. The former is particularly important because otherwise, you'd have to manually iterate over characters until you find the end of strings or numbers, which is unacceptably slow in MATLAB.