示例#1
0
// Función que realiza, para los elementos de los vectores de funciones optimistas, pesimistas y de no-repeticion,
// iters iteraciones con las semillas de seeds. Nótese que se llama a tareas_rp(...opts[k], pess[k], reps[k]...) iters veces, 
// no a todas las combinaciones posibles entre opts, pess y reps.
void generaTest(v_f_opt_t opts, v_f_pes_t pess, v_noRep_t reps, int iters, std::ostream* out, bool drawSol) {
	if (opts.size() != pess.size() || opts.size() != reps.size() || opts.size() == 0) {
		std::cerr << "Error, los tamaños de los vectores de prueba no coinciden o son nulos" << std::endl;
		return;
	}
	v_seed_t seeds;
	for (int i = 0; i < iters; i++) {
		seeds.push_back(rand());
	}

	vtaskId_t solMejor;
	taskt_t tiempoTareas = INF;
	uint64_t maxExpandedNodes, expandedNodes;

	for (int i = 0; i < opts.size(); i++) {
		for (int k = 0; k < iters; k++) {
			generaTareas(seeds[k]);
			uint64_t ini = GetTimeMs64();
			tareas_rp(solMejor, tiempoTareas, expandedNodes, maxExpandedNodes, opts[i], pess[i], reps[i]);
			uint64_t end = GetTimeMs64();
			(*out) << end - ini << " " << expandedNodes << " " << maxExpandedNodes << std::endl;
			if (drawSol) {
				draw(solMejor);
			}
		}
		*out << std::endl;
	}
}
示例#2
0
int main(int argc, char** argv) {
	uint32_t matchAlgorithm = 0;
	const char* outputFile = "displacements.result";
	const char* imageSequenceFolder = nullptr;

	const ImageProc::ImageProc* imProc = new ImageProc::ImageProcBase();
	Draw::DrawInterface* drawer = new Draw::Draw();
	const Displacement::DisplacementInterface* displacement = new Displacement::DisplacementBase();
	InputMethod::InputMethodInterface* inputMethod = nullptr;
	OutputMethod::OutputImageSequence* outputMethod = new OutputMethod::OutputImageSequence();

	const Descriptor::DescriptorInterface* descriptor = nullptr;
	const Match::MatcherInterface* matcher = nullptr;

	if (argc > 1) {
		imageSequenceFolder = argv[1];
	} else {
		LOG_ERROR("Image sequence folder not defined");
		return -1;
	}
	if (argc > 2) {
		matchAlgorithm = (uint32_t) std::strtoul(argv[2], NULL, 10);
	}
	if (argc > 3) {
		outputFile = argv[3];
	}
	LOG_INFO("Using %s", getMethodPname(matchAlgorithm));

	if (getInputMethod(imageSequenceFolder, &inputMethod) != GBL::RESULT_SUCCESS) {
		LOG_ERROR("Could not deduce a valid input method");
		return -1;
	}

	if (getExecutors(matchAlgorithm, &descriptor, &matcher) != GBL::RESULT_SUCCESS) {
		LOG_ERROR("Could not get valid descriptor and matcher. Define a valid algorithm to be used.");
		return -1;
	}

	clock_t tStart = clock();
	int64_t startTime = GetTimeMs64();
	std::vector<GBL::Displacement_t> displacements = findTheBall(imageSequenceFolder, imProc, *drawer, *descriptor, *matcher, *displacement, *inputMethod, *outputMethod);
	int64_t endTime = GetTimeMs64();
	float_t totalTimeElapsed = (float_t) (clock() - tStart) / CLOCKS_PER_SEC;
	LOG(stdout, "TIME", "CPU time of processing stage: %f s", totalTimeElapsed);
	LOG(stdout, "TIME", "Execution time of processing stage: %f s", (float_t ) (endTime - startTime) / 1000.0f);

	if (writeResults(outputFile, displacements) != GBL::RESULT_SUCCESS) {
		LOG_WARNING("Could not write results to file %s", outputFile);
	}

	delete imProc;
	delete descriptor;
	delete matcher;
	delete displacement;
	delete drawer;
	delete inputMethod;

	return 0;
}
示例#3
0
// Función que llama al algoritmo de vuelta atrás con poda, utilizando las funciones pasadas como parámetro para las podas
uint64_t test(f_opt_t estimacionOptimista, f_pes_t estimacionPesimista, f_noRep_t funcionNoRep) {
	vtaskId_t solMejor;
	taskt_t tiempoTareas = INF;
	uint64_t maxExpandedNodes, expandedNodes;

	uint64_t ini = GetTimeMs64();
	tareas_rp(solMejor, tiempoTareas, expandedNodes, maxExpandedNodes, estimacionOptimista, estimacionPesimista, funcionNoRep);
	uint64_t end = GetTimeMs64();
	if(!silent) {
		std::cout << std::endl << "Nodos expandidos: " << expandedNodes << std::endl;
		std::cout << "Máximo numero de nodos simultáneos: " << maxExpandedNodes << std::endl;
		std::cout << "Tiempo de ejecución(ms): " << end - ini << std::endl << std::endl ;
		draw(solMejor);
		std::cout << std::endl << "Tiempo maximo (tareas): " << tiempoTareas << std::endl << std::flush;
	}

	return end - ini;
}
示例#4
0
static void benchmark(unsigned int numberOfItems)
{
    WeightedTrieWithDump* t = new WeightedTrieWithDump();
    unsigned long seed[] = {0x42, 0x69, 0x69, 0x42};
    MTRand_int32 mt(seed, 4);
    unsigned int i;

    std::cout << "Benchmark size: " << numberOfItems << std::endl;

    std::cout << "Generating test data...";
    uint256** hashes = new uint256*[numberOfItems];
    for (i = 0; i < numberOfItems; i++) {
        hashes[i] = &(GenerateRandomTxID(mt));
    }
    std::cout << "done" << std::endl;

    // prefill with n items so that trie is never empty, otherwise
    // benchmarks will be optimistic
    for (i = 0; i < numberOfItems; i++) {
        if (!t->Add(GenerateRandomTxID(mt), 10)) {
            std::cout << i << " (prefill) couldn't be added" << std::endl;
        }
    }
    // add
    uint64_t startTime = GetTimeMs64();
    for (i = 0; i < numberOfItems; i++) {
        if (!t->Add(*(hashes[i]), 10)) {
            std::cout << i << " couldn't be added" << std::endl;
        }
    }
    uint64_t endTime = GetTimeMs64();
    std::cout << "add required " << ((double)(endTime - startTime) * 1000.0 / numberOfItems) << " us per op" << std::endl;
    // remove
    startTime = GetTimeMs64();
    for (i = 0; i < numberOfItems; i++) {
        t->Remove(*(hashes[i]));
    }
    endTime = GetTimeMs64();
    std::cout << "remove required " << ((double)(endTime - startTime) * 1000.0 / numberOfItems) << " us per op" << std::endl;
    // get
    startTime = GetTimeMs64();
    // Accumulate return value of GetByCumulativeWeight() so that compiler does
    // not optimise it away.
    intptr_t keyPtr = 0;
    for (i = 0; i < numberOfItems; i++) {
        keyPtr += (intptr_t)t->GetByCumulativeWeight(mt() % (10 * (numberOfItems + numberOfItems)));
    }
    // Display keyPtr so that compiler does not consider it to be unused
    std::cout << "Ignore this number: " << keyPtr << std::endl;
    endTime = GetTimeMs64();
    std::cout << "query required " << ((double)(endTime - startTime) * 1000.0 / numberOfItems) << " us per op" << std::endl;
}
float SimpleTimer::stop()
{
	__int64 end_time = GetTimeMs64();
	return ( float )( end_time - start_time );
}
void SimpleTimer::start()
{
	start_time = GetTimeMs64();
}
示例#7
0
uint64 
Bench::TimeElapsed() const{
    uint64 start = GetTimeMs64();
    fFunction();
    return GetTimeMs64() - start;
}