> No, you aren't suppose to be able to see how the word-count works by looking at this code. The complexity happens elsewhere, setting up the state-machine. This is like most of the reason I opened this article. I wish they'd spend more time talking about this. In fact, most of the README covers details that are important, but, irrelevant to their algorithmic improvements. Maybe they expect you to open up the code, b…
Wc2: Investigates optimizing 'wc', the Unix word count program
11–20 of 157 posts
Re: Wc2: Investigates optimizing 'wc', the Unix word count program
#12> This state machine approach always results in the same speed, regardless of input. This is strange to me, shouldn't it be O(N) with the size of the input ? Or maybe in this benchmark the inputs are small enough that the difference isn't measurable ?
Re: Wc2: Investigates optimizing 'wc', the Unix word count program
#13 wc --unicode
wc --bomRe: Wc2: Investigates optimizing 'wc', the Unix word count program
#14https://dreampuf.github.io/GraphvizOnline/#digraph%20StateMa...
digraph StateMachine { rankdir=LR; size="8,5"; node [shape = circle];
LookingForWord -> InsideWord [label="Non-space"];
LookingForWord -> LookingForWord [label="Space"];
LookingForWord -> Newline [label="Newline"];
LookingForWord -> LookingForWord [label="Other"];
Newline -> InsideWord [label="Non-space"];
Newline -> LookingForWord [label="Space"];
Newline -> Newline [label="Newline"];
Newline -> LookingForWord [label="Other"];
InsideWord -> ContinueWord [label="Non-space"];
InsideWord -> LookingForWord [label="Space"];
InsideWord -> Newline [label="Newline"];
InsideWord -> LookingForWord [label="Other"];
ContinueWord -> ContinueWord [label="Non-space"];
ContinueWord -> LookingForWord [label="Space"];
ContinueWord -> Newline [label="Newline"];
ContinueWord -> LookingForWord [label="Other"];
}EDIT: Under peer pressure, I checked it and it correctly reflects the code apart from being designed for one specific line ending sequence (as it should, being an example optimized for brevity).
As for the replies, as opposed to my approach, I'm sure when you're browsing research papers, you're doing a full reproducibility study for each one. I'm sorry I commented, I should have waited for you to post your results.
Re: Wc2: Investigates optimizing 'wc', the Unix word count program
#15I wanted to take a peek the state diagram (ASCII version). But I was feeling lazy, so apologies for having ChatGPT do the work for me. I wasn't going for correctness and didn't check it. If you're like me, here you go: https://dreampuf.github.io/GraphvizOnline/#digraph%20StateMa... digraph StateMachine { rankdir=LR; size="8,5"; node [shape = circle]; LookingForWord -> InsideWord [label="Non-space"]; LookingForWord ->…
Re: Wc2: Investigates optimizing 'wc', the Unix word count program
#16> No, you aren't suppose to be able to see how the word-count works by looking at this code. The complexity happens elsewhere, setting up the state-machine. This is like most of the reason I opened this article. I wish they'd spend more time talking about this. In fact, most of the README covers details that are important, but, irrelevant to their algorithmic improvements. Maybe they expect you to open up the code, b…
Re: Wc2: Investigates optimizing 'wc', the Unix word count program
#17> This state machine approach always results in the same speed, regardless of input. This is strange to me, shouldn't it be O(N) with the size of the input ? Or maybe in this benchmark the inputs are small enough that the difference isn't measurable ?
But yes, a bigger file does take longer to process.
Re: Wc2: Investigates optimizing 'wc', the Unix word count program
#18Sorry, no, this is completely wrong. There are other reasons NFAs or DFAs might be preferable, and there are other performance considerations as far as backtracking is concerned, but NFA implementations do not backtrack. I mean, they could, but they don’t, and in common usage a “NFA regex implementation” means a non-backtracking one (that goes through all input once with a bag of states in hand and advances each one of them on each step), whereas a “backtracking regex implementation” means one that doesn’t use automata at all (and is usually worst-case exponential in the input).
What this is actually talking about is a streaming parser. Just call it like it is, it’s an OK term that sees plenty of usage.
[What you could mention here is PEG parsers, because even linear PEG implementations may need to keep O(input) state and thus are essentially incapable of streaming, unlike LL or LR ones; and GLR et al. can be even worse, for what it’s worth. But this is a much more obscure topic.]
Re: Wc2: Investigates optimizing 'wc', the Unix word count program
#19Re: Wc2: Investigates optimizing 'wc', the Unix word count program
#20"Many programmers think pointer-arithmetic is faster." Don't modern compilers make this statement false (i.e., both approaches are implemented via the same machine instructions)?