increment slowdown
"Ruud H.G. van Tol" <[email protected]> Tue, 10 Mar 2026 14:05:38 +0100
| Newsgroups | gmane.comp.mathematics.pari.user |
|---|---|
| Message-ID | <[email protected]> |
oeis.A005228: ? lista1(len)= my(r=List(1), d=1); while(#r<len, setsearch(r, d++) && d++; listput(~r, r[#r]+d)); Vec(r); ? lista1(10001)[-10..-1] cpu time = 227 ms, real time = 228 ms. %7 = [50793733, 50803858, 50813984, 50824111, 50834239, 50844368, 50854498, 50864629, 50874761, 50884894] ? lista2(len)= my(r=List(1), d=1); while(#r<len, d++; setsearch(r, d) && d++; listput(~r, r[#r]+d)); Vec(r); ? lista2(10001)[-10..-1] cpu time = 18 ms, real time = 18 ms. %12 = [50793733, 50803858, 50813984, 50824111, 50834239, 50844368, 50854498, 50864629, 50874761, 50884894] The first variant has the d++ inside the setsearch() call, and is much slower. Is that a bug? -- Greetings Ruud