Sujet : Re: A very slow program
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 02. Oct 2024, 16:41:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vdjm2s$394jf$1@dont-email.me>
References : 1
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 16.09.2024 00:45, Student Project wrote:
[ snip C program ]
/*
The result on my slow machine:
Program takes an average of 0.018000 seconds to find 78498 primes.
*/
Note, this is the same runtime magnitude that Unix'es 'primes'
command needs to run on 1000000 numbers to create 78498 primes
(0m00.01s) [on my very old (and slow) Unix system].
Is there a point in still writing own programs for that task?
I see some point when examining performance optimizations (as
someone downthread seems to have done). For cryptography there's
certainly demands for yet faster (parallelized) algorithms - if
quantum system algorithms don't make it superfluous (lately, or
in near future). But for cryptography you'd anyway need larger
numeric domains, beyond '[long]* integer' arithmetics. (I don't
know whether the [downthread posted] C++ code was designed to
support arbitrary length arithmetics.)
Optimized algorithms of new methods alone might not be a C topic.
But given your posting name, "Student Project", I suppose you're
anyway just using it as example for learning the C language?
For ordinary users it's probably sufficient to use an existing
program; on Unix 'primes 1 1000000000' runs in about 8 seconds.
And it's checking 2^32 numbers in 50 seconds (including 'wc'
and creating output [suppressed by redirection]), generating
50847534 primes. A simple prime test of some "arbitrary large"
number runs in no time, as does factorization of numbers with
the Unix'es 'factor' program. Just a simple command line call.
That existing 'primes' program also has some limit; the man page
documents a value of 4294967295, but no error message is created
for values up to around 1.8446744*10^19 on my system.
Janis