Slice Filename Benchmark

by Ricardo Fernández Serrata

Version 2 (February 27, 2022)

Download (14 downloads)

Shows the timings of `split` with subscript, "lastIndexOf" with `substr`, and `matches`, when they extract a substring after the last slash in a random large text file.

In my device `matches` was the fastest, followed by "lastIndexOf", then `split`. I was surprised by `matches`, but the difference between "LIO" and `split` was expected.

The following is an explanation of why this happens. It may be wrong, because I don't know the source code of these functions:

`matches`: Java compiles regexes, so it recognized that the only important part of the text was at the end, which caused it to iterate over the chars in reverse order.

LIO: this is an emulation, so it doesn't iterate backwards. It reverses the FULL string, then iterates forwards, and passes the index to `susbtr` to slice the text.

`split`: tries to find ALL occurrences of "/", iterating and slicing multiple parts of the full string. Only for the vast majority of the data to be discarded by the subscript

3.0 average rating from 1 reviews

5 stars
4 stars
3 stars
2 stars
1 star

Rate and review within the app in the Community section.