-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic implementation of iString and comparative testing code.
- Loading branch information
1 parent
ac7b7c3
commit 071ca79
Showing
2 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,46 @@ | ||
#include <string/iString.h> | ||
#include "string/iString.h" | ||
#include <chrono> | ||
#include <iostream> | ||
using string = MiracleForest::string::iString; | ||
|
||
void compare() | ||
{ | ||
char c[] = "emmm,测试utf-8字符串999"; | ||
char* d = c + 5; | ||
{ | ||
// 获取开始时间 | ||
auto start = std::chrono::high_resolution_clock::now(); | ||
for (size_t i = 0; i < 10000000; i++) { std::string str(d); } | ||
auto end = std::chrono::high_resolution_clock::now(); | ||
// 计算耗时,并将结果转换为毫秒 | ||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); | ||
|
||
int main() { return 0; } | ||
// 输出结果 | ||
std::cout << "标准库Function took " << duration.count() << " ms to execute." << std::endl; | ||
} | ||
{ | ||
// 获取开始时间 | ||
auto start = std::chrono::high_resolution_clock::now(); | ||
for (size_t i = 0; i < 10000000; i++) { string str(d); } | ||
auto end = std::chrono::high_resolution_clock::now(); | ||
// 计算耗时,并将结果转换为毫秒 | ||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); | ||
|
||
// 输出结果 | ||
std::cout << "自定义字符串Function took " << duration.count() << " ms to execute." << std::endl; | ||
} | ||
} | ||
int main() | ||
{ | ||
system("chcp 65001"); | ||
char8_t c[] = u8"emmm,测试utf-8字符串999"; | ||
string str("emmm,测试utf-8字符串999"); | ||
// string str1(c); | ||
std::cout << (const char*)c << std::endl; | ||
std::cout << str << std::endl; | ||
char any; | ||
std::cout << "按下任意键开始测试" << std::endl; | ||
std::cin >> any; | ||
for (size_t i = 0; i < 10; i++) { compare(); } | ||
return 0; | ||
} |