Generator/Exponential: Difference between revisions

m
Line 33:
This is considerably simpler, and faster, and arguably easier to reason about, than the generator implementation. (In a quick benchmark, the direct implementation was 185 times faster and used half of the space of the generator implementation -- despite the fact that it "wasted" 3 times the computation of the generator. The generator only needed to compute squares up to 33 squared, where the quick implementation arbitrarily computed squares up to 100, but the more complicated logic of the generator also had a cost. That said, note that both implementations could be tuned for somewhat better performance (less than a factor of 10, in both cases).]
 
However, here is an natural implementation of a generator (with the caveatscaveat that generators are not very natural, in J):
 
<lang j>coclass 'generator'
6,962

edits