Re: Re: Flat Short of MEMORY_BLOCK
"Franck Arnaud" <[email protected]>
| Newsgroups | gmane.comp.lang.eiffel.gobo.general |
|---|---|
| Message-ID | <[email protected]> |
Brian Heilig: > Because: > > buffer[i] = a_byte; > > is faster than: > > memcpy (&buffer[i], &a_byte, 1); Huh? Why should it be? It's essentially doing the same thing, and a C compiler should know how to optimise memcpy! As usual, you must do benchmarks before making such claims: [email protected]:~$$ gcc -O2 arraymemcpy.c ; ./a.out array 130 memcpy 130 Test code: #include <string.h> #include <sys/times.h> #define MAX 100000 #define REPEAT 5000 void test(int how) { int r; int i; char a_byte = 12; char buffer[MAX]; if (!how) { for (r=0;r<REPEAT;r++) { for (i=0;i<MAX;i++) { buffer[i] = a_byte; } } } else { for (r=0;r<REPEAT;r++) { for (i=0;i<MAX;i++) { memcpy (&buffer[i], &a_byte, 1); } } } } main () { struct tms before, after; times (&before); test (0); times (&after); printf ("array %d\n", after.tms_utime - before.tms_utime); times (&before); test (1); times (&after); printf ("memcpy %d\n", after.tms_utime - before.tms_utime); } ------------------------ Yahoo! Groups Sponsor ---------------------~--> Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511 http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/saFolB/TM ---------------------------------------------------------------------~-> To Post a message, send it to: [email protected] To Unsubscribe, send a blank message to: [email protected] Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/gobo-eiffel/ <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/