Sieve of Eratosthenes: Difference between revisions

Content deleted Content added
Chkas (talk | contribs)
No edit summary
Line 12,488: Line 12,488:


Further optimizations as in maximum wheel factorization (a further about five times faster), multi-threading (for a further multiple of the effective number of cores used), maximum loop unrolling (about a factor of two for smaller base primes), and other techniques for higher ranges (above 16 billion in this case) can be used with increasing code complexity, but there is little point when using prime enumeration as output: ie. one could reduce the composite number culling time to zero but it would still take about 2.8 seconds to enumerate the results over the billion range in the case of this processor.
Further optimizations as in maximum wheel factorization (a further about five times faster), multi-threading (for a further multiple of the effective number of cores used), maximum loop unrolling (about a factor of two for smaller base primes), and other techniques for higher ranges (above 16 billion in this case) can be used with increasing code complexity, but there is little point when using prime enumeration as output: ie. one could reduce the composite number culling time to zero but it would still take about 2.8 seconds to enumerate the results over the billion range in the case of this processor.

=={{header|Tailspin}}==
<lang tailspin>
templates sieve
def limit: $it
[ 2..$limit ] -> @
1 -> #
$@ !

<..$@::length ?($@($it) * $@($it) <..$limit>)>
templates sift
def prime: $it
$prime * $prime -> @
[ $@sieve... -> # ] -> @sieve
<..~$@>
$it !
<$@~..>
$@ + $prime -> @
$it -> #
end sift

$@($it) -> sift !
$it + 1 -> #
end sieve

1000 -> sieve ...-> '$it; ' -> stdout
</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==