コード例 #1
0
/*
 * Test the performance of the substr() function of our strType
 */
float StropBencher::substr(int numRuns, int strType) {

	float startTime = currTime();
	std::string longStr("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
	std::string subStr;
	int pos;

	switch(strType) {

	case MAUTIL_STRING:

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				subStr = longStr.substr(pos = rand()%(longStr.length()-1), rand()%(longStr.length()-pos));
			}
		}
		printf("subStr: %s", subStr.c_str()); //force the compiler to actually do the operations because subStr is used!
		

		/*case STD_STRING: TODO Will have to wait until STL is implemented*/

	}
    return currTime() - startTime;

}
コード例 #2
0
ファイル: main.cpp プロジェクト: lishuhuakai/CS
void bench(bool longLog)
{
	muduo::Logger::setOutput(asyncOutput);

	int cnt = 0;
	const int kBatch = 1000;
	muduo::string empty = " ";
	muduo::string longStr(3000, 'X');
	longStr += " ";

	for (int t = 0; t < 30; ++t)
	{
		muduo::Timestamp start = muduo::Timestamp::now();
		for (int i = 0; i < kBatch; ++i)
		{
			LOG_INFO << "Hello 0123456789" << " abcdefghijklmnopqrstuvwxyz "
			         << (longLog ? longStr : empty)
			         << cnt;
			++cnt;
		}
		muduo::Timestamp end = muduo::Timestamp::now();
		printf("%f\n", timeDifference(end, start) * 1000000 / kBatch);
		struct timespec ts = { 0, 500 * 1000 * 1000 };
		nanosleep(&ts, NULL);
	}
}
コード例 #3
0
ファイル: test_util.cpp プロジェクト: lbl1985/toolbox_c
// -----------------------------------------------------
// ---------------  TEST3: num2str2  -------------
// -----------------------------------------------------
bool num2str2Test(){
	int intNum = 20;
	long longNum = 200000;
	double doubleNum = 20.3;
	double negNum = -20.3;
	int len = 5;

	std::string intStr(num2str2<int>(intNum, len));
	std::string longStr(num2str2<long>(longNum, len));
	std::string doubleStr(num2str2<double>(doubleNum, len));
	std::string negStr(num2str2<double>(negNum, len));

	if (intStr.compare("00020") != 0 || longStr.compare("200000") != 0 || doubleStr.compare("020.3") != 0 || negStr.compare("-20.3") != 0 )
	{
		return false;
	}
	return true;
}
コード例 #4
0
/*
 * Test the performance of string comparisons on our strType
 */
float StropBencher::compare(int numRuns, int strType, int cmpType) {

	float startTime = currTime();
	bool ret;
	std::string longStr("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
	std::string eq("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
	std::string notEq("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghilj#kmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
	std::string less("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljjkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz"); //2 j:s in a row makes this string lexiographically less than longStr
	std::string more("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljmkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz"); //a m after the j makes this string lexiographically more than longStr
	int pos;

	switch(strType) {

	case MAUTIL_STRING:

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				if(cmpType == 0)
					ret = longStr == eq;
				else if(cmpType == 1)
					ret = longStr != notEq;
				else if(cmpType == 2)
					ret = longStr <= more;
				else if(cmpType == 3)
					ret = longStr >= less;
				else if(cmpType == 4)
					ret = longStr < less;
				else
					ret = longStr > less;

			}
		}
//		printf("ret: %d", ret); //force the compiler to actually do the operations because subStr is used!

		/*case STD_STRING: TODO Will have to wait until STL is implemented*/

	}
    return currTime() - startTime;

}
コード例 #5
0
ファイル: graficadortorta.c プロジェクト: vf9QaDj/T01
void graficotorta(int n, long cantidad[], int estado[]) {

    gdImagePtr imagen;
    FILE *archivo;
    char titulo[513];
    char etiqueta[512];
    int blanco, negro, color;
    gdFontPtr fuente = gdFontGetSmall();
    
    imagen = gdImageCreateTrueColor(IMG_WIDTH, IMG_HEIGHT);

    int i;
    int angEtiqueta, xEtiqueta, yEtiqueta;
    float eqgrados;
    int iniciotrozo, fintrozo;
    long suma = 0;
    int aprox;
    for (i=0; i<n; i++) {    
        suma = suma + cantidad[i];
    }
    eqgrados = 360.0/suma;
    
    if (imagen) {
        blanco = gdImageColorAllocate(imagen, 255, 255, 255);
        negro = gdImageColorAllocate(imagen, 0, 0, 0);
        // Pintamos el fondo Blanco
        gdImageFill(imagen, 0, 0, blanco);
        iniciotrozo = 0;
        for (i=0; i<n; i++) {
            fintrozo = (int) iniciotrozo+cantidad[i]*eqgrados;
            angEtiqueta = (iniciotrozo + fintrozo) / 2;
            xEtiqueta = cos(angEtiqueta*PI/180) * 220 + 400;
            yEtiqueta = sin(angEtiqueta*PI/180) * 220 + 290;
            // Color
            color = gdImageColorAllocate(imagen, color_aleatoreo(), color_aleatoreo(), color_aleatoreo());
            //Pintamos fondo el trozo
            gdImageFilledArc(imagen, 400, 300, 400, 400, iniciotrozo, fintrozo, color, gdArc);       
            //Etiqueta de peticion
            memset(etiqueta, 0, 513);
            snprintf(etiqueta, 512, "peticion %s",intStr(estado[i]));
            gdImageString(imagen, fuente, xEtiqueta-25, yEtiqueta, (unsigned char *) etiqueta, negro);
            //Correccion de aproximacion para el porcentaje
            aprox = cantidad[i] * 1000 / suma;
            aprox = aprox%10;
            if (aprox>=5)
                aprox = 1;
            else
                aprox = 0;
            //Etiqueta de porcentaje
            memset(etiqueta, 0, 513);
            snprintf(etiqueta, 512, "%s%%",longStr(cantidad[i]*100/suma+aprox));
            if (cantidad[i]*100/suma<3){      //Para que la etiqueta sea legible
                xEtiqueta = xEtiqueta + 52;
                yEtiqueta = yEtiqueta - 15;
            }
            gdImageString(imagen, fuente, xEtiqueta, yEtiqueta+15, (unsigned char *) etiqueta, negro);
            iniciotrozo = (int) iniciotrozo+cantidad[i]*eqgrados;
        }

        //Pintamos borde del circulo
        gdImageArc(imagen, 400, 300, 400, 400, 0, 360, negro);
        // Coloco el título
        memset(titulo, 0, 513);
        snprintf(titulo, 512, "Peticiones Por Estado");
        gdImageString(imagen, fuente, (int) IMG_WIDTH * 0.4, 25, (unsigned char *) titulo, negro);
        // Pintamos Borde
        gdImageLine(imagen, BORDE_ANCHO, BORDE_ALTO, (IMG_WIDTH - BORDE_ANCHO), BORDE_ALTO, negro); //linea horiz superior
        gdImageLine(imagen, BORDE_ANCHO, (IMG_HEIGHT - BORDE_ALTO), (IMG_WIDTH - BORDE_ANCHO), (IMG_HEIGHT - BORDE_ALTO), negro); //linea horiz inferior
        gdImageLine(imagen, BORDE_ANCHO, BORDE_ALTO, BORDE_ANCHO, (IMG_HEIGHT - BORDE_ALTO), negro); //linea vertical izquierda
        gdImageLine(imagen, (IMG_WIDTH - BORDE_ANCHO), BORDE_ALTO, (IMG_WIDTH - BORDE_ANCHO), (IMG_HEIGHT - BORDE_ALTO), negro); //linea horiz derecha
        // Guardar imagen
        archivo = fopen("graficot.jpg", "wb");
        if (archivo != NULL) {
            gdImageJpeg(imagen, archivo, 100);
            fclose(archivo);
        }
        gdImageDestroy(imagen);
    }
 
}
コード例 #6
0
    /** Utility to test striping of space characters. By altering the parameters
    *  you can test the different strip flavours:
    *  The first parameter controls whether you want to 'strip' leading characters, 
    *  trailing characters or both charactersr. The other two parameters are used to 
    *  test variants of testing spaces - viz. a) test when the type 
    *  of 'stripping' has been explicitly specified as trailing / nothing has specified. 
    *  and b) test when the character to be specified has been explicitly specifed as ' ' or 
    *  nothing has been specified. 
    */
    void utlTestStripSpaces(UtlString::StripType sType, \
                   bool specifyStripType, bool specifyChar)
    {

        // We need a string which has both leading and
        // trailing spaces.
        string longStr("         ") ; 
        longStr.append(longAlphaString) ; 
        longStr.append("        ") ; 

        // To evaluate the expected string resulting out of a strip(trail), 
        // construct a string with only the longAlphaString and leading) spaces
        string tmpStringForTrailing("         ") ; 
        tmpStringForTrailing.append(longAlphaString) ; 
        
        // To evaluate the expected string resulting out of a strip(leading), 
        // construct a string with only the longAlphaString and trailing spaces
        string tmpStringForLeading(longAlphaString) ; 
        tmpStringForLeading.append("        ") ;
        
        const char* expectedForLeading = tmpStringForLeading.data() ; 
        const char* expectedForTrailing = tmpStringForTrailing.data() ; 
        // If both sides are striped then  the expected
        // string would just be longAlphaString
        const char* expectedForBoth = longAlphaString ; 
        

        const TestStripDataStructure testData[] = { \
               { "empty char*", "", ' ', \
                     "", "", "" }, \
               { "regular char* w/o spaces", "A String", ' ', \
                     "A String", "A String", "A String" }, \
               { "regular char* w trailing spaces", "A String  ", ' ', \
                     "A String", "A String  ", "A String" }, \
               { "regular char* w leading spaces", "  A String", ' ', \
                     "  A String", "A String", "A String" }, \
               { "alpha-num char* w/o spaces", "String12#2A", ' ',\
                     "String12#2A", "String12#2A", "String12#2A" }, \
               { "alpha-num char* w trailing spaces", "String12#2A  ", ' ', \
                     "String12#2A", "String12#2A  ", "String12#2A" }, \
               { "alpha-num char* w both spaces", "  String12#2A  ", ' ', \
                     "  String12#2A", "String12#2A  ", "String12#2A" }, \
               { "space only char*", "     ", ' ', \
                     "", "", ""} , \
               { "Very long char*", longStr.data(), ' ', \
                     expectedForTrailing, expectedForLeading, expectedForBoth } \
        } ;

        // create the first part of the message based on the type of striping to be done!
        string prefix("Test the strip(")  ; 
        if (specifyStripType)
        {
            switch(sType)
            {
                case UtlString::trailing :
                    prefix.append("trailing") ; 
                    break ; 
                case UtlString::leading :
                    prefix.append("leading") ; 
                    break ; 
                case UtlString::both :
                    prefix.append("both") ; 
                    break ; 
            }
        }   
        if (specifyChar) 
        {
            prefix.append(", ' '") ; 
        } 
        prefix.append(") for a string made of ") ; 

        const int testCount = sizeof(testData) / sizeof(testData[0]) ;
        for (int i = 0 ; i < testCount; i++)
        {
            UtlString testString(testData[i].input) ;
            UtlString returnString ;
            string Message ; 
            if (specifyStripType)
            {
                if(specifyChar)
                {
                    returnString = testString.strip(sType, ' ');
                }
                else
                {
                    returnString = testString.strip(sType) ;
                }
            }
            else
            {
                KNOWN_EFENCE_BUG("Segmentation fault w/efence", "XPL-9");
                returnString = testString.strip() ;
            }

            const char* expectedValue = ""; 
            switch(sType)
            {
                case UtlString::trailing:
                    expectedValue = testData[i].expectedForStripTrailing ; 
                    break ; 
                case UtlString::leading:
                    expectedValue = testData[i].expectedForStripLeading; 
                    break ; 
                case UtlString::both:
                    expectedValue = testData[i].expectedForStripBoth ; 
                    break ; 
            }
            TestUtilities::createMessage(2, &Message, prefix.data(), \
                            testData[i].testDescription) ; 
            
            CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), \
                        string(expectedValue), \
                        string(returnString.data())) ;
        }
     } //utlTestStripSpaces