Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Speed: VFP 6 vs VB
Message
From
12/09/1998 01:24:20
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00135486
Message ID:
00135766
Views:
23
>Do you have another way to convert from int to a 10 character blank padded string?

try this:
#include <time.h>
#include <strstrea.h>

extern "C" {

__declspec(dllexport) int test(int iterations);

}

__declspec(dllexport) int test(int iterations) {

	strstream sTest;

	sTest.width(10);	// set the width to 10
        // sTest.str() returns a pointer to the internal
        // char array and "freezes" the array.
        // sTest.rdbuf->freeze( 0 ) "unfreezes" the array.

	clock_t tStart = clock();

	for ( int i = 0; i < iterations; i++ ) {

		sTest << i;
	}

	return (int) (clock() - tStart);

}
called by:
#define ITERATIONS	10000

local cstr, lnow, i
cstr = ''

lnow = seconds()
for i = 1 to ITERATIONS
	cstr = cstr + str(i)
endfor 

? "Visual Foxpro Time: " + str((seconds() - lNow) * 1000)

declare Integer test in e:\test2\Release\test2.dll as test ;
	Integer Iterations

? "C++ Stream Time: " + str(test(ITERATIONS))

clear all
Compared to VFP 5.0a, the C++ takes aprox. half the time. See how VFP 6.0 fairs.

The C++ io stream classes are capable of doing easy formatting much more flexibly than the old C stdio functions.

This example could be faster if the max size of the string were set so dynamic memory allocation is not necessary.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform