当前位置: 首页>>代码示例>>C++>>正文


C++ Timer::GetElapsedMilliseconds方法代码示例

本文整理汇总了C++中Timer::GetElapsedMilliseconds方法的典型用法代码示例。如果您正苦于以下问题:C++ Timer::GetElapsedMilliseconds方法的具体用法?C++ Timer::GetElapsedMilliseconds怎么用?C++ Timer::GetElapsedMilliseconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Timer的用法示例。


在下文中一共展示了Timer::GetElapsedMilliseconds方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BenchRandomDigit

void BenchRandomDigit(void(*f)(double, char*), const char* fname, FILE* fp) {
	printf("Benchmarking randomdigit %-20s ... ", fname);

	char buffer[256];
	double minDuration = std::numeric_limits<double>::max();
	double maxDuration = 0.0;

	for (int digit = 1; digit <= RandomDigitData::kMaxDigit; digit++) {
		double* data = RandomDigitData::GetData(digit);
		size_t n = RandomDigitData::kCount;

		double duration = std::numeric_limits<double>::max();
		for (unsigned trial = 0; trial < kTrial; trial++) {
			Timer timer;
			timer.Start();

			for (unsigned iteration = 0; iteration < kIterationPerDigit; iteration++) {
				for (size_t i = 0; i < n; i++) {
					f(data[i], buffer);
					//if (trial == 0 && iteration == 0 && i == 0)
					//	printf("%.17g -> %s\n", data[i], buffer);
				}
			}

			timer.Stop();
			duration = std::min(duration, timer.GetElapsedMilliseconds());
		}

		duration *= 1e6 / (kIterationPerDigit * n); // convert to nano second per operation
		minDuration = std::min(minDuration, duration);
		maxDuration = std::max(maxDuration, duration);
		fprintf(fp, "randomdigit,%s,%d,%f\n", fname, digit, duration);
	}
	printf("[%8.3fns, %8.3fns]\n", minDuration, maxDuration);
}
开发者ID:4ker,项目名称:dtoa-benchmark,代码行数:35,代码来源:main.cpp

示例2: BenchRandom

void BenchRandom(void(*f)(double, char*), const char* fname, FILE* fp) {
	printf("Benchmarking      random %-20s ... ", fname);

	char buffer[256];
	double* data = RandomData::GetData();
	size_t n = RandomData::kCount;

	double duration = std::numeric_limits<double>::max();
	for (unsigned trial = 0; trial < kTrial; trial++) {
		Timer timer;
		timer.Start();

		for (unsigned iteration = 0; iteration < kIterationForRandom; iteration++)
			for (size_t i = 0; i < n; i++)
				f(data[i], buffer);

		timer.Stop();
		duration = std::min(duration, timer.GetElapsedMilliseconds());
	}

	duration *= 1e6 / (kIterationForRandom * n); // convert to nano second per operation

	fprintf(fp, "random,%s,0,%f\n", fname, duration);

	printf("%8.3fns\n", duration);
}
开发者ID:4ker,项目名称:dtoa-benchmark,代码行数:26,代码来源:main.cpp

示例3: BenchSequential

void BenchSequential(void(*f)(double, char*), const char* fname, FILE* fp) {
	printf("Benchmarking  sequential %-20s ... ", fname);

	char buffer[256] = { '\0' };
	double minDuration = std::numeric_limits<double>::max();
	double maxDuration = 0.0;

	int64_t start = 1;
	for (int digit = 1; digit <= 17; digit++) {
		int64_t end = start * 10;

		double duration = std::numeric_limits<double>::max();
		for (unsigned trial = 0; trial < kTrial; trial++) {
			int64_t v = start;
			Random r;
			v += ((int64_t(r()) << 32) | int64_t(r())) % start;
			double sign = 1;
			Timer timer;
			timer.Start();
			for (unsigned iteration = 0; iteration < kIterationPerDigit; iteration++) {
				double d = v * sign;
				f(d, buffer);
				//printf("%.17g -> %s\n", d, buffer);
				sign = -sign;
				v += 1;
				if (v >= end)
					v = start;
			}
			timer.Stop();
			duration = std::min(duration, timer.GetElapsedMilliseconds());
		}

		duration *= 1e6 / kIterationPerDigit; // convert to nano second per operation
		minDuration = std::min(minDuration, duration);
		maxDuration = std::max(maxDuration, duration);
		fprintf(fp, "%s_sequential,%d,%f\n", fname, digit, duration);
		start = end;
	}

	printf("[%8.3fns, %8.3fns]\n", minDuration, maxDuration);
}
开发者ID:4ker,项目名称:dtoa-benchmark,代码行数:41,代码来源:main.cpp

示例4: NetworkException

bool CGUL::Network::HTTPRequest::PerformRequest(UInt32 timeout)
{
    response = "";
    responseHead = "";
    responseBody = "";

    if (!sock->IsConnected())
    {
        throw NetworkException(NetworkExceptionCode::FAILED_HTTP_REQUEST, NetworkExceptionReason::SOCKET_INVALID);
    }

    sock->Send((const void*)request.GetCString(), request.GetSize());

    char buffer[1024];

    // Wait for the response.
    Timer timeoutTimer;
    timeoutTimer.Start();
    while (sock->Peek(buffer, 1) == 0 && (timeoutTimer.GetElapsedMilliseconds() < timeout || timeout == 0))
    {
        if (!sock->IsConnected())
        {
            throw NetworkException(NetworkExceptionCode::FAILED_HTTP_REQUEST, NetworkExceptionReason::SOCKET_INVALID);
        }
    }
    timeoutTimer.Stop();

    if (timeoutTimer.GetElapsedMilliseconds() >= timeout && timeout != 0)
    {
        throw NetworkException(NetworkExceptionCode::FAILED_HTTP_REQUEST, NetworkExceptionReason::TIMEOUT);
    }

    //Get the headers length.
    int headSize = 0;
    sock->Peek(buffer, 1024);
    CGUL::String bufferString = buffer;
    headSize = bufferString.FindFirstOf("\r\n\r\n")+4;

    //Get the reponse's head.
    char* bufferHead = new char[headSize];
    sock->Receive(bufferHead, headSize);
    responseHead += bufferHead;

    //Parse the Response Header
    ParseResponseHead();

    //Get the reponse's body.
    int amount = 0;

    switch (header.transferEncoding)
    {
        case HTTPTransferEncoding::CONTENT_LENGTH:
        {
            unsigned int count = 0;
            while (sock->IsConnected())
            {
                unsigned int size = 1024;
                if (count + size > header.contentLength)
                {
                    size = header.contentLength - count;
                }

                char* buff = new char[size];
                amount = sock->Receive((void*)buff, size);
                count += amount;
                if (amount > 0)
                {
                    responseBody += EncodeString(buff, size);
                }

                if (count >= header.contentLength)
                {
                    break;
                }
            }
            break;
        }

        case HTTPTransferEncoding::CHUNKED:
        {
            char * sizeBuffer = new char[64];

            while (sock->IsConnected())
            {
                //Get the size.
                amount = sock->Peek(sizeBuffer, 64);
                if (amount <= 0)
                {
                    break;
                }

                String sizeString = "";
                for (int i = 0; i < amount; i++)
                {
                    if (sizeBuffer[i] == '\r')
                    {
                        if (sizeBuffer[i+1] == '\n')
                        {
                            break;
                        }
//.........这里部分代码省略.........
开发者ID:Zethes,项目名称:CGUL,代码行数:101,代码来源:HTTPRequest.cpp


注:本文中的Timer::GetElapsedMilliseconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。