Java’s Scanner vs String.split() vs StringTokenizer; which should I use?

Did some metrics around these in a single threaded model and here are the results I got. ~~~~~~~~~~~~~~~~~~Time Metrics~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Tokenizer | String.Split() | while+SubString | Scanner | ScannerWithCompiledPattern ~ ~ 4.0 ms | 5.1 ms | 1.2 ms | 0.5 ms | 0.1 ms ~ ~ 4.4 ms | 4.8 ms | 1.1 ms … Read more

Python split string in moving window

The itertools examples provides the window function that does just that: from itertools import islice def window(seq, n=2): “Returns a sliding window (of width n) over data from the iterable” ” s -> (s0,s1,…s[n-1]), (s1,s2,…,sn), … ” it = iter(seq) result = tuple(islice(it, n)) if len(result) == n: yield result for elem in it: result … Read more

String.Split VS. Regex.Split?

Regex.Split is more capable, but for an arrangement with basic delimitting (using a character that will not exist anywhere else in the string), the String.Split function is much easier to work with. As far as performance goes, you would have to create a test and try it out. But, don’t pre-optimize, unless you know that … Read more