首页 > 代码库 > [C++] Running time and Integer to String
[C++] Running time and Integer to String
#pragma once #include "Inf.hpp" #include <stdint.h> #include <string> #include <iostream> #include <sstream> #define BUFFER_SIZE 1048576 std::string int2str(int32_t p_vint); std::string int2str_oss(int32_t p_vint); std::string int2str(int32_t p_vint) { char str[11] = { 0 }; int bits = 0, temp = 0; for (int i = 0; p_vint > 1; ++bits, ++i) { temp = p_vint; p_vint /= 10; str[i] = temp - p_vint * 10 + 0x30; } for (int i = 0; i < bits / 2; i++) { str[i] ^= str[bits - 1 - i]; str[bits - 1 - i] ^= str[i]; str[i] ^= str[bits - 1 - i]; } str[bits] = 0; return std::string(str); } std::string int2str_oss(int32_t p_vint) { std::ostringstream oss; oss << p_vint; return oss.str(); }
Running Time:
#include <Windows.h> int main() { double time = 0; double counts = 0; LARGE_INTEGER nFreq; LARGE_INTEGER nBeginTime; LARGE_INTEGER nEndTime; QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&nBeginTime);//开始计时 //encode("d:/bgm_.txt", "d:/bgm2.txt"); //test //for (int i = 0; i < 1000000; i++) // int2str(i); //5.33s //for (int i = 0; i < 1000000; i++) // int2str_oss(i); //23.53s QueryPerformanceCounter(&nEndTime);//停止计时 time = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) / (double)nFreq.QuadPart; std::cout << "Running Time:" << time * 1000 << "ms" << std::endl; return 0;
[C++] Running time and Integer to String
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。