-
-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Try the code
sieve(n) =
{
my(S,p); /* necessary to avoid creating global S,p */
S = apply((x)->1,[1..n]);
for(p=2,floor(sqrt(n)),
if(S[p],forstep(m=p+p,n,p,S[m]=0));
);
return(select((x)->S[x],[2..n]));
};
c = gettime();
w = getwalltime();
print(sieve(10^6)==select((p)->isprime(p),[1..10^6]));
print("Time: ", strtime(gettime() - c));
print("Time: ", strtime(getwalltime() - w));
c = gettime();
w = getwalltime();
print(length(sieve(10^7)));
print("Time: ", strtime(gettime() - c));
print("Time: ", strtime(getwalltime() - w));
in the kernel and in the terminal.
In the terminal I obtain:
Time: 2,535 ms
Time: 2,644 ms
*** apply: Warning: increasing stack size to 1024000000.
*** select: Warning: increasing stack size to 2048000000.
664579
Time: 31,440 ms
Time: 32,261 ms
and in the Kernel
Time: 4,479 ms
Time: 5,030 ms
*** Warning: increasing stack size to 1024000000.
*** select: Warning: increasing stack size to 1200001024.
664579
Time: 51,229 ms
Time: 52,096 ms
any insight on how to fix this?
My alternative is to have a kernel based on pexpect, but then I can't easily support completion
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels