示例#1
0
// 模拟交互过程的函数
unsigned _int64 TestHL::ProtocolFun(const int& tag){
	// 获取被选标签的信息
	string sql;
	sql = "select [Id], [Key] from Tags_HL where Num=";
	sql.append(itostr(tag));
	adoConn.GetRecordSet(sql.c_str());
	if (adoConn.m_pRecordset->GetState() == adStateClosed || adoConn.m_pRecordset->GetRecordCount() == 0)
	{
		cout << endl << "Tag[" << tag << "] isn't in DataBase." << endl;
		return 0;
	}

	// 生成查询信息
	Request_Info req;
	req.id= adoConn.m_pRecordset->GetCollect("Id").uintVal;
	req.key = adoConn.m_pRecordset->GetCollect("Key").uintVal;
	adoConn.CloseRecordset();

	// 计时器
	MyTimer timer;
	// 初始化随机数生成器
	minstd_rand0 minrand(timer.GetBegin());

	timer.Start();

	// 调用模拟标签的函数
	Response_Info res = TagFun(req);

	// 调用阅读器的函数
	Result_Info result = ReaderFun(res);

	// 计时器终止
	timer.Stop();

	return  timer.GetTime();

}
示例#2
0
int main(int argc, char *argv[]) {
    if (argc != 4) {
        printf("Insertion Sort C++\n\n"\
               "uso  : %s metodo insertion_sort input_file output_file\n"\
               "ejm. : %s is input/n1m.txt output/o-n1m.txt\n",
               argv[0], argv[0]);

        exit(-1);
    }

    //Número de palabras
    int num_palabras;

    // Object containing information to control a stream
    FILE *infile_ptr = NULL;
    FILE *outfile_ptr = NULL;

    //Open file for input operations. The file must exist.
    infile_ptr  = fopen(argv[2], "r+");
    outfile_ptr = fopen(argv[3], "w+");

    // Timer
    MyTimer mt;
    int tiempo_total = 0;

    printf("Leer archivo... ");
    mt.Start();

    // read count
    char count[MAX_ANCHO_LINEA];

    // Get - Leer numero de lineas ubicadas en la cabecera del archivo
    // esto es para determinar cuanto de memoria debemos separar
    // el valor es solo aproximado, para una mejor gestion
    if (fgets(count, MAX_ANCHO_LINEA, infile_ptr) != NULL) {
        num_palabras = atoi(count);
    }

    // Array de lineas
    LINE *w_arr;
    w_arr = (LINE *)calloc(num_palabras, sizeof(LINE));

    NODE *n_arr, *n_head, *n_cur;
    n_arr  = (NODE *)calloc(num_palabras, sizeof(NODE));
    n_head = n_arr;

    // read words
    int linea;
    int num_lineas = 0;
    for (linea = 0; !feof(infile_ptr); linea++) {
        // using fgets() is faster, but there is '\n' at the end of the string.
        fgets(w_arr[linea].data, MAX_ANCHO_LINEA, infile_ptr);
        n_arr[linea].vp = w_arr[linea].data;
        //printf("n_arr[%i]=%s\n", linea, n_arr[linea].vp);
        n_arr[linea].next = &n_arr[linea + 1];
        ++num_lineas;
    }
    n_arr[linea - 1].next = NULL;

    fclose(infile_ptr);
    mt.Stop();

    printf("%d ms\n", (int)mt.d_costTime);
    tiempo_total += (int)mt.d_costTime;

    // sorting
    printf("Ordenando... ");
    mt.Start();

    // obtener Método de Ordenamiento de los parámetros
    if ( strcmp(argv[1], "insertion_sort") == 0) {
        insertion_sort(n_arr, num_lineas - 1 );
    } else {
        printf("Metodo no Implementado... ");
        return 0;//exit
    }


    mt.Stop();
    printf("%d ms\n", (int)mt.d_costTime);
    tiempo_total += (int)mt.d_costTime;

    // write to file
    printf("Escribir archivo... ");
    mt.Start();
    fputs(count, outfile_ptr);
    n_cur = n_head;
    while (1) {
        fputs(n_cur->vp, outfile_ptr);
        if (n_cur->next == NULL) break;
        n_cur = n_cur->next;
    }
    fclose(outfile_ptr);

    mt.Stop();
    printf("%d ms\n", (int)mt.d_costTime);
    tiempo_total += (int)mt.d_costTime;

    printf("Tiempo total en: %d ms\n", tiempo_total);

    free(w_arr);
    free(n_arr);

    return 0;
}
示例#3
0
int main( int argc, const char ** argv ) {

    // Get params
    // pm-simple.exe polyADegree polyBDegree
    if (argc != 3) {
        std::cout << "Simple Random Poly Multiply C++" << std::endl;
        std::cout << "Uso: pm-simple.exe polyADegree polyBDegree" << std::endl;
        std::cout << "Ejm: pm-simple.exe 5 6" << std::endl;
        return 0;
    }

    // Set vars
    int rdADegree = std::atoi( argv[1] );
    int rdBDegree = std::atoi( argv[2] );

    // Conditions:
    // Array coefficients corresponding to degrees
    // in ascending order (i.e. {5, 0, 10, 6} = 5 + 10x^2 + 6x^3

    // Generate two polys, on random sizes
    // Bug en Windows si le das mas de 7
    // [1-2] Range
    // unsigned int rdADegree = (unsigned int)rand() % 2 + 1 ;
    // unsigned int rdBDegree = (unsigned int)rand() % 2 + 1;
#ifdef TRACE
    std::cout << "rdADegree: " << rdADegree  << std::endl;
    std::cout << "rdBDegree: " << rdBDegree  << std::endl;
#endif

    // Coef rdADegree + 1
    std::vector<int> coefA( rdADegree + 1 );
    std::vector<int> coefB( rdBDegree + 1);

    // Setting random values
    // Populate random
    srand(time(NULL));
    for (unsigned int i = 0; i < coefA.size(); i++) {
        // [-10,10] Range
        // totalOfIntegers = limitSuperior - limitInferior + 1
        coefA[i] = rand() % 21 + (-10);
    }

    for (unsigned int j = 0; j < coefB.size(); j++) {
        // [-10,10] Range
        coefB[j] = rand() % 21 + (-10);
    }

#ifdef TRACE
    // Print Random Polys
    std::cout << "Random Poly A " << std::endl;
    print_poly( coefA );

    std::cout << "Random Poly B "  << std::endl;
    print_poly( coefB );
#endif

    MyTimer mt;
    unsigned int tiempoTotal = 0;
    mt.Start();

    std::vector<int> producto = multiply(coefA,coefB);

#ifdef TRACE
    std::cout << std::endl << "AxB: " << std::endl;
    print_poly(producto);
#endif

    // stop timer
    mt.Stop();
    tiempoTotal += (int) mt.d_costTime;

    std::cout << "Tiempo total multiplicacion (milisegundos): " << tiempoTotal << " ms" << std::endl;

    return 0;
}