Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Speed Test for Comparison |
| Date | 2011-12-10 21:40 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <jc0jka$dc4$1@dont-email.me> (permalink) |
| References | <9kc99pFurU1@mid.individual.net> <lnty5ak6vk.fsf@nuthaus.mib.org> <9khmneF4udU1@mid.individual.net> |
"Mel Smith" <med_cutout_syntel@aol.com> wrote in message
news:9khmneF4udU1@mid.individual.net...
> for i := 1 to 1000000
> str( i / 1000 ) // no assignment of the return value
> next
You want to compare C code that does this *directly*, or C code that
implements some arbitrary virtual machine that does the same job?
In either case, the timings will be dominated by the time needed to convert
floating point numbers to strings, and, if the implementation does proper
string handling, by the overheads of creating and discarding a million short
strings.
Any comparison is anyway likely to be meaningless because you are testing
one arbitrary implementation against another.
FWIW, a simple sprintf() loop in C took about 1 second on my machine. Your
str(i/1000) loop in one of my scripting languages, with proper string
handling, took 2 seconds to execute a million times. This language is
usually much slower than C. So the actual task, rather than language
overheads, seems to be dominating execution time.
However, given the complicated-looking C code that your language generates,
I'm surprised it isn't much slower. Your first step might be to simply find
out how long the task itself might be expected to take, but I'm not sure why
you can't do this for yourself:
#include <stdio.h>
int main(void) {
int i;
char str[100];
for (i=0; i<1000000; ++i) {
sprintf(str,"%f",i/1000.0);
}
}
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Speed Test for Comparison "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-08 10:09 -0700
Re: Speed Test for Comparison Richard Sanders <lnr729@gmail.com> - 2011-12-08 11:19 -0800
Re: Speed Test for Comparison "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-08 13:13 -0700
Re: Speed Test for Comparison "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-08 13:18 -0700
Re: Speed Test for Comparison Seebs <usenet-nospam@seebs.net> - 2011-12-08 20:41 +0000
Re: Speed Test for Comparison Ben Pfaff <blp@cs.stanford.edu> - 2011-12-08 12:49 -0800
Re: Speed Test for Comparison Seebs <usenet-nospam@seebs.net> - 2011-12-08 21:53 +0000
Re: Speed Test for Comparison Seebs <usenet-nospam@seebs.net> - 2011-12-08 20:41 +0000
Re: Speed Test for Comparison "BartC" <bc@freeuk.com> - 2011-12-08 21:43 +0000
Re: Speed Test for Comparison ImpalerCore <jadill33@gmail.com> - 2011-12-08 13:58 -0800
Re: Speed Test for Comparison Keith Thompson <kst-u@mib.org> - 2011-12-08 14:58 -0800
Re: Speed Test for Comparison "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-10 11:28 -0700
Re: Speed Test for Comparison "BartC" <bc@freeuk.com> - 2011-12-10 21:40 +0000
Re: Speed Test for Comparison "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-10 19:26 -0700
Re: Speed Test for Comparison Keith Thompson <kst-u@mib.org> - 2011-12-10 13:49 -0800
csiph-web