Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Speed Test for Comparison

Reply
Thread Tools

Speed Test for Comparison

 
 
Keith Thompson
Guest
Posts: n/a
 
      12-08-2011
"Mel Smith" <(E-Mail Removed)> writes:
> I have included below 56 speed test results when using the C-based
> Harbour language along with the MinGw 4.6.1 C compiler
>
> This test package was generated by running the Harbour compiler to
> create C modules which were then compiled by the MinGw compiler, and then
> linked..
>
> The executable was then run to create the test results below.
>
> I'd be interested in getting some purely C-based test results based on
> any of the 56 tests I ran below.
>
> Each test below was run 1,000,000 times. The results below are stated in
> decimal seconds.
>
> The assignment operator is ':=' rather than '='
>

[snip]
>
> The & means a 'macro' compilation whereby the string is compiled and run
> at runtime.

[...]
[ T028: eval( bc := { |x| f1( x ) }, i ) ]......................0.50

I had to manually copy-and-paste one of your test cases for this
followup, because for some reason you put all the test results after a
sig delimiter ("-- ").

So what you're looking for is, for example, benchmark results for C code
equivalent to whatever

eval( bc := { |x| f1( x ) }, i )

means in your language. Are you asking us to manually translate your
code snippets to C, then write wrappers to perform and report the
timings?

Speaking only for myself, that's far more work than I'm willing to do.
If you provided the C code you want benchmarked, someone *might* be more
likely to run it for you.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Mel Smith
Guest
Posts: n/a
 
      12-10-2011
Hi:

I have extracted Test 019 (T019) from the test suite, and have recoded
part of it to show the translation and compilation sequence to .C code

and at the bottom of this post I have include the Harbour source code for
the test

-Mel Smith


***** following is the C code for Test 019 (T019) **********
This test took approx 1.52 seconds on my machine noted above

/*
* Harbour 3.1.0dev (Rev. 17129)
* MinGW GNU C 4.6.1 (32-bit)
* Generated C source from "source\T019.prg"
*/

#include "hbvmpub.h"
#include "hbpcode.h"
#include "hbinit.h"
#include "hbxvm.h"


HB_FUNC( MAIN );
HB_FUNC_EXTERN( SCROLL );
HB_FUNC_EXTERN( SETPOS );
HB_FUNC( T019 );
HB_FUNC_EXTERN( QOUT );
HB_FUNC_EXTERN( STR );
HB_FUNC_EXTERN( INKEY );
HB_FUNC_EXTERN( HB_SECONDSCPU );
HB_FUNC_EXTERN( PROCNAME );


HB_INIT_SYMBOLS_BEGIN( hb_vm_SymbolInit_T019 )
{ "MAIN", {HB_FS_PUBLIC | HB_FS_FIRST | HB_FS_LOCAL}, {HB_FUNCNAME( MAIN )},
NULL },
{ "SCROLL", {HB_FS_PUBLIC}, {HB_FUNCNAME( SCROLL )}, NULL },
{ "SETPOS", {HB_FS_PUBLIC}, {HB_FUNCNAME( SETPOS )}, NULL },
{ "T019", {HB_FS_PUBLIC | HB_FS_LOCAL}, {HB_FUNCNAME( T019 )}, NULL },
{ "QOUT", {HB_FS_PUBLIC}, {HB_FUNCNAME( QOUT )}, NULL },
{ "STR", {HB_FS_PUBLIC}, {HB_FUNCNAME( STR )}, NULL },
{ "INKEY", {HB_FS_PUBLIC}, {HB_FUNCNAME( INKEY )}, NULL },
{ "HB_SECONDSCPU", {HB_FS_PUBLIC}, {HB_FUNCNAME( HB_SECONDSCPU )}, NULL },
{ "PROCNAME", {HB_FS_PUBLIC}, {HB_FUNCNAME( PROCNAME )}, NULL }
HB_INIT_SYMBOLS_EX_END( hb_vm_SymbolInit_T019, "source\\T019.prg", 0x0,
0x0003 )

#if defined( HB_PRAGMA_STARTUP )
#pragma startup hb_vm_SymbolInit_T019
#elif defined( HB_DATASEG_STARTUP )
#define HB_DATASEG_BODY HB_DATASEG_FUNC( hb_vm_SymbolInit_T019 )
#include "hbiniseg.h"
#endif

HB_FUNC( MAIN )
{
do {
hb_xvmFrame( 1, 0 );
hb_xvmSetLine( 5 );
hb_xvmPushFuncSymbol( symbols + 1 );
if( hb_xvmDo( 0 ) ) break;
hb_xvmPushFuncSymbol( symbols + 2 );
hb_xvmPushInteger( 0 );
hb_xvmPushInteger( 0 );
if( hb_xvmDo( 2 ) ) break;
hb_xvmSetLine( 8 );
hb_xvmPushFuncSymbol( symbols + 3 );
if( hb_xvmFunction( 0 ) ) break;
hb_xvmPopLocal( 1 );
hb_xvmSetLine( 17 );
hb_xvmPushFuncSymbol( symbols + 4 );
hb_xvmPushLocal( 1 );
if( hb_xvmArrayItemPush( 1 ) ) break;
hb_xvmPushStringConst( " *** ", 5 );
if( hb_xvmPlus() ) break;
hb_xvmPushFuncSymbol( symbols + 5 );
hb_xvmPushLocal( 1 );
if( hb_xvmArrayItemPush( 2 ) ) break;
hb_xvmPushInteger( 5 );
hb_xvmPushInteger( 2 );
if( hb_xvmFunction( 3 ) ) break;
if( hb_xvmPlus() ) break;
if( hb_xvmDo( 1 ) ) break;
hb_xvmSetLine( 20 );
hb_xvmPushFuncSymbol( symbols + 4 );
if( hb_xvmDo( 0 ) ) break;
hb_xvmSetLine( 21 );
hb_xvmPushFuncSymbol( symbols + 4 );
hb_xvmPushStringConst( "Press any Key to Exit: ", 23 );
if( hb_xvmDo( 1 ) ) break;
hb_xvmSetLine( 22 );
hb_xvmPushFuncSymbol( symbols + 6 );
hb_xvmPushInteger( 0 );
if( hb_xvmDo( 1 ) ) break;
hb_xvmSetLine( 23 );
hb_xvmRetNil();
/* *** END PROC *** */
} while( 0 );
}

HB_FUNC( T019 )
{
HB_BOOL fValue;
do {
hb_xvmFrame( 2, 0 );
hb_xvmSetLine( 30 );
hb_xvmPushNil();
hb_xvmPopLocal( 2 );
hb_xvmSetLine( 31 );
hb_xvmPushFuncSymbol( symbols + 7 );
if( hb_xvmFunction( 0 ) ) break;
hb_xvmPopLocal( 1 );
hb_xvmSetLine( 33 );
hb_xvmPushInteger( 1 );
hb_xvmPushUnRef();
hb_xvmPopLocal( 2 );
goto lab00002;
lab00001: ;
hb_xvmSetLine( 34 );
hb_xvmPushFuncSymbol( symbols + 5 );
hb_xvmPushLocal( 2 );
if( hb_xvmDivideByInt( 1000 ) ) break;
if( hb_xvmDo( 1 ) ) break;
hb_xvmSetLine( 33 );
if( hb_xvmLocalIncPush( 2 ) ) break;
lab00002: ;
if( hb_xvmGreaterThenIntIs( 1000000, &fValue ) ) break;
if( !fValue )
goto lab00001;
hb_xvmSetLine( 37 );
hb_xvmPushFuncSymbol( symbols + 7 );
if( hb_xvmFunction( 0 ) ) break;
hb_xvmPushLocal( 1 );
if( hb_xvmMinus() ) break;
hb_xvmPopLocal( 1 );
hb_xvmSetLine( 43 );
hb_xvmPushFuncSymbol( symbols + 8 );
if( hb_xvmFunction( 0 ) ) break;
hb_xvmPushStringConst( ": ", 2 );
if( hb_xvmPlus() ) break;
hb_xvmPushStringConst( "str(i/1000)", 11 );
if( hb_xvmPlus() ) break;
hb_xvmPushLocal( 1 );
hb_xvmArrayGen( 2 );
hb_xvmRetValue();
/* *** END PROC *** */
} while( 0 );
}
**************** end of C code **********************

************************************************** **********
Following is the harbour code that generated the C Code above

function main()
local aResult

// clear the screen
CLS

// then call the Test Function T019
aResult := T019()

// Now Print the results to the Screen:
// (The question mark '?') skips a line and print the String Expression
// to its right)
// 1st element is a character string
// 2nd element must be converted from a numeric to a character string
// so that it can be printed. The format here has two decimals

? aResult[1] + " *** " + str(aResult[2],5,2)

// wait for a key press before exiting
?
? "Press any Key to Exit: "
inkey(0)
return nil

// Here is the test function for making a string of an real number
// after taking an incremented integer and dividing it by 1000,
// and doing this 1,000,000 times

function T019()
local time, i:= nil
time = hb_secondscpu() // get the cpu seconds to this moment for this app

for i := 1 to 1000000
str( i / 1000 ) // no assignment of the return value
next

time := hb_secondscpu() - time // compute cpu seconds used

// now return a 2-element array containing
// 1. The Procedure Name and the Expression to be analyzed
// 2. The time in decimal seconds taken to run the loop

return { procname() + ": " + 'str(i/1000)', time }

************* end of Harbour Code **********



 
Reply With Quote
 
 
 
 
BartC
Guest
Posts: n/a
 
      12-10-2011
"Mel Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-10-2011
"Mel Smith" <(E-Mail Removed)> writes:
> I have extracted Test 019 (T019) from the test suite, and have recoded
> part of it to show the translation and compilation sequence to .C code
>
> and at the bottom of this post I have include the Harbour source code for
> the test

[snip]

Ok, that's 1 out of 56.

Just how much work do you expect us to do for you?

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Mel Smith
Guest
Posts: n/a
 
      12-11-2011
Bart said:

> 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);
> }
> }



Hi Bart:

Thanks for the code:

I'm going to use my MinGw 4.6.1 compiler and try to compile it and run
it myself.

Thank you !

(I need nothing more than this !)

and to Keith: I don't expect anything more. Bart has provided what I wish.


-Mel Smith


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison of 2 files and generating the output based on comparison Deepu Perl Misc 1 02-07-2011 03:09 PM
Price Comparison Service. Best Deal. Special Coupon atBest-Price-Comparison.com rapee Digital Photography 0 03-14-2008 06:46 AM
speed speed speed a.metselaar Computer Support 14 12-30-2003 03:34 AM
java tool to test disk i/o, processor speed, and network speed efiedler Java 1 10-09-2003 03:36 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments