Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Speed: VFP 6 vs VB
Message
De
12/09/1998 01:24:20
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00135486
Message ID:
00135766
Vues:
22
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform