当前位置: 首页 > news >正文

【18位数据次方提高数据输出速度】2022-3-9

实在是无法忍受W10输出数据那么慢W7需要2分钟输出数据W10则需要10分钟完成W7需要3分钟W10则需要15分钟完成输出数据,虽然W10运算速度比W7快很多但是加上输出速度总体完成时间居然差不多!随着使用数组超过百万W7数据输出时间也变长,随着数组数据超百万每运算1万次方历时也变得较长,快速保存每次运算好的数据很有必要,只好再次出手,写提高输出文本速度只能用尾部叠加法不能用插入法和叠加头部法:

void 二的次方数组(_int64* 数, _int64 长, _int64 次)
{_int64 溢 = 0, 序 = 长 - 1, 次方 = 1; std::string wb = "";二的次方数组读取文本("..\\Debug\\回复专用\\", "二次方数据*.txt", 数, 长, 次方);char 时间[128]; _strtime_s(时间, 128); printf("时间:%s 次方%d\n", 时间, 次方);if (次方 == 1)数[序] = 1; else;while (次方 && 序 > -1){if (数[序] > 0){数[序] = 数[序] * 2 + 溢;溢 = 数[序] / 1E+18;数[序] -= 溢*1E+18;if (次方 % 40000 == 0)wb += std::to_string(数[序]) + "\n"; else;--序;}else{数[序] += 溢;if (wb != ""){if (溢> 0)wb += std::to_string(数[序]) + "\n"; else;_strtime_s(时间, 128); printf("时间:%s ", 时间); std::cout << 次方 << " " << 长 - 序;写入文本("..\\Debug\\回复专用\\二次方数据倒序" + std::to_string(次方 + 1) + ".txt", wb/* + std::to_string(序)*/);_strtime_s(时间, 128); printf(":%s数据输出完成。\n", 时间); wb = "";}else;if (++次方 > 次 || 数[0] > 0){_strtime_s(时间, 128); printf("时间:%s ", 时间); std::cout << 次方 << " " << 长 - 序;写入文本("..\\Debug\\回复专用\\二次方数据" + std::to_string(次方) + ".txt", std::to_string(序) + "\n");while (++序 < 长)写入文本("..\\Debug\\回复专用\\二次方数据" + std::to_string(次方) + ".txt", std::to_string(数[序]) + "\n");_strtime_s(时间, 128); printf(":%s数据输出完成。\n", 时间);次方 = 0;}else;if (次方 % 10000 == 0){string 标题 = "VsC++:" + std::to_string(次方) + "编程论坛回复专用=》VsC++:二次方数组1E7。";system(("title " + 标题).data());}else;序 = 长 - 1; 溢 = 0;}}
}
void 二的次方数组读取文本(std::string 路径, std::string 文件名, _int64* 数, _int64 长, _int64& 次方)
{_finddata_t file;std::string newPath = 路径 + 文件名, 读取 = "";_int64 cf = 0; int j = 0, jj = 0;intptr_t HANDLE = _findfirst((路径 + 文件名).c_str(), &file);if (HANDLE == -1L)std::cout << "无法匹配文件夹路径" << std::endl;elsedo{if (file.attrib){newPath = 路径 + file.name;j = newPath.find("数据") + 4;if (newPath.find("倒序") != std::string::npos)j = newPath.find("倒序") + 4;jj = newPath.find(".txt");cf = _atoi64(newPath.substr(j, jj - j).c_str());if (次方 < cf)次方 = cf, 读取 = newPath; else;}else;} while (_findnext(HANDLE, &file) == 0);_findclose(HANDLE);std::string 读 = ""; bool k = (读取.find("倒序") == std::string::npos);int 序 = (k ? 0 : 长 - 1), 位 = 0;std::ifstream 文件(读取);if (!文件.eof()){while (getline(文件, 读))if (k){if (序 == 0)序 = _atoi64(读.c_str());else数[++序] = _atoi64(读.c_str());}else{数[序] = _atoi64(读.c_str());--序;}//if (!k)数[++序] = 0;文件.close();}else;//std::cout << 数[k ? 序 : ++序] << "\t" << 读 << "\n";std::cout << 数[k ? 序 : ++序] << "\t" << 读 << "\t" << 数[长 - 1] << "\n";
}

文本名称的次方数-1为实际次方,内容顺序文件第一行为数组序,倒序结尾无数组序。

void 二的次方数组读取文本(std::string 路径, std::string 文件名, _int64 (*数)[10000000], int 长, _int64& 次方)
{_finddata_t file;std::string newPath = 路径 + 文件名, 读取 = "";_int64 cf = 0; int j = 0, jj = 0;intptr_t HANDLE = _findfirst((路径 + 文件名).c_str(), &file);if (HANDLE == -1L)std::cout << "无法匹配文件夹路径" << std::endl;elsedo{if (file.attrib){newPath = 路径 + file.name;j = newPath.find("数据") + 4;if (newPath.find("倒序") != std::string::npos)j = newPath.find("倒序") + 4;jj = newPath.find(".txt");cf = _atoi64(newPath.substr(j, jj - j).c_str());if (次方 < cf)次方 = cf, 读取 = newPath; else;}else;} while (_findnext(HANDLE, &file) == 0);_findclose(HANDLE);std::string 读 = "";bool k = (读取.find("倒序") == std::string::npos);_int64 序 = (k ? 0 : 长 - 1), 位 = 0, 组 = 0;std::ifstream 文件(读取);if (!文件.eof()){while (getline(文件, 读))if (k){if (序 == 0)序 = _atoi64(读.c_str());else{//if (序 == 长 && 组 < 1)++组, 序 = 长 - 1;数[组][++序] = _atoi64(读.c_str());}}else{数[组][序] = _atoi64(读.c_str());if (--序 < 0 && 组 < 1) ++组, 序 = 长 - 1;//--序;}文件.close();}else;//std::cout << 数[组][序] << "\t" << 读 << "\n";std::cout << 数[组][k ? 序 : ++序] << "\t" << 读 << "\t" << 数[组][长 - 1] << "\n";
}
void 二的次方数组(_int64 (*数)[10000000], _int64 长, _int64 次)
{_int64 溢 = 0, 序 = 长 - 1, 次方 = 1, 组 = 0; std::string wb = "";二的次方数组读取文本("..\\Debug\\回复专用\\", "二次方数据*.txt", 数, 长, 次方);char 时间[128]; _strtime_s(时间, 128); printf("时间:%s 次方%d\n", 时间, 次方);if (次方 == 1)数[组][序] = 1; else;while (次方 && 序 > -1){if (数[组][序] > 0){数[组][序] = 数[组][序] * 2 + 溢;溢 = 数[组][序] / 1E+18;数[组][序] -= 溢*1E+18;if (次方 % 40000 == 0) wb += std::to_string(数[组][序]) + "\n"; else;if (--序 < 0 && 组 < 1) ++组, 序 = 长 - 1;// --序;}else{数[组][序] += 溢;if (wb != ""){if (溢> 0)wb += std::to_string(数[组][序]) + "\n"; else;_strtime_s(时间, 128); printf("时间:%s ", 时间); std::cout << 次方 << " " << 长 - 序;写入文本("..\\Debug\\回复专用\\二次方数据倒序" + std::to_string(次方 + 1) + ".txt", wb/* + std::to_string(序)*/);_strtime_s(时间, 128); printf(":%s数据输出完成。\n", 时间); wb = "";}else;if (++次方 > 次 || 数[组][0] > 1E+18)// || 次方 % 100000 == 0{_strtime_s(时间, 128); printf("时间:%s ", 时间); std::cout << "次方" << 次方 << " 数量" << 长 - 序 << " ";写入文本("..\\Debug\\回复专用\\二次方数据" + std::to_string(次方) + ".txt", std::to_string(序) + "\n");while (++序 < 长){写入文本("..\\Debug\\回复专用\\二次方数据" + std::to_string(次方) + ".txt", std::to_string(数[组][序]) + "\n");显示进度(长, 序);}_strtime_s(时间, 128); printf(":%s数据保存完成。\n", 时间);//if (次方 > 次 || 数[组][0] > 1E+18)次方 = 0;}if (次方 % 10000 == 0){std::string 标题 = "VsC++:" + std::to_string(次方);system(("title " + 标题).data());}序 = 长 - 1; 组 = 溢 = 0;}}
}

http://www.dtcms.com/a/286970.html

相关文章:

  • 多线程-1-基础写法
  • 顺理成章学RL-1(based Stanford CS234 Reinforcement Learning)
  • Webstorm 前端断点调试
  • pom.xml文件中的${}变量从哪里传值
  • Couchbase 可观测性最佳实践
  • ModbusRTU转profibus网关与涡街液体流量计通讯读取流量计温度
  • Android性能优化之启动优化
  • python学智能算法(二十三)|SVM-几何距离
  • Python 入门手札:从 0 到会--第九天Python的模块化编程--模块、包以及常见系统模块和第三方模块总结
  • 微店平台商品详情接口技术实现指南
  • C语言:预处理
  • 软件测试全谱系深度解析:从单元到生产的质量保障体系
  • JavaScript笔记
  • 功能安全之BIST的基本原理
  • 关于tftp怎么把res文件夹传输给开发板的操作步骤:
  • 通过代码识别大小端模式
  • 先让 AI 学会害怕,再让它握紧方向盘
  • Unity 多人游戏框架学习系列六
  • YT Config Tool 添加FreeRTOS模块
  • 【linux V0.11】kernel(水)
  • 2025年6月GESP(C++二级): 幂和数
  • 游戏盾能否保护业务免受DDoS攻击吗?
  • Django母婴商城项目实践(五)- 数据模型的搭建
  • 【Python练习】 049. 编写一个函数,实现简单的文本编辑器功能,支持增删改查
  • 你的品牌需要一个AI首席内容官——解构BrandCraft如何解决内容创作的终极痛点
  • 枚举算法入门
  • 【2025/07/18】GitHub 今日热门项目
  • 北斗网格位置码详解:经纬度到二维网格码的转换(非极地)
  • 针对BERT模型的理解
  • 04-三思而后行:解锁AI的“内心戏”