Generator/Exponential: Difference between revisions

Content added Content deleted
Line 31: Line 31:
529 576 625 676 784 841 900 961 1024 1089</lang>
529 576 625 676 784 841 900 961 1024 1089</lang>


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. Note that both implementations could be tuned for somewhat better performance (less than a factor of 10, in both cases).]
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).]


That said, here is an natural implementation of a generator:
However, here is an natural implementation of a generator:


<lang j>coclass 'generator'
<lang j>coclass 'generator'