惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
L
LINUX DO - 最新话题
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
L
LINUX DO - 热门话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Visual Studio Blog
O
OpenAI News
AI
AI
Hacker News: Ask HN
Hacker News: Ask HN
V2EX - 技术
V2EX - 技术
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
Spread Privacy
Spread Privacy
Y
Y Combinator Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
T
The Blog of Author Tim Ferriss
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
N
News and Events Feed by Topic
Project Zero
Project Zero
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog
G
Google Developers Blog

皓子的小站

网站字体应用之坑——font-family 篇 糟糕的 meta name="theme-color" How to Automatically Track Newly Supported ESLint Rules in Oxlint How to Gradually Migrate from ESLint to Oxlint (Without Breaking Everything) 静态资源预压缩:零运行时开销,极致节省带宽 CVE-2025-70886 Proof of Concept (PoC) | A Script to Crash Halo CMS Comment Backend 自定义网页鼠标指针——一段曲折的旅程 CVE-2025-70886 漏洞复现/PoC | 一个脚本让 Halo CMS 评论后台瘫痪 2025 年终总结 & 博客两周年 老用户专享!已有 Halo 专业版授权可免费升级商业版 自动追踪 Oxlint 对 ESLint 规则的新增支持 Halo 贡献者证书与实体周边盲盒开箱 博客评论系统指南 CDN 回源跟随配置导致登录异常问题排查 SCDN 免费赞助计划:助力高质量博客&博客圈 锐捷校园网:网络共享与带宽叠加方案(哈理工案例) ESLint 到 Oxlint 渐进式迁移快速上手指南 Fixing Vite Breaking Inline JS & CSS in Thymeleaf Templates 解决 Vite 破坏 Thymeleaf 模板内联 JS & CSS 的方法 我的博客,为什么是月更? 博客俱乐部一周年纪念品开箱 网站字体加载之坑——format 篇 经历 1000000000 次 DDoS 请求攻击后,我总结了三条经验 题解分享:[AtCoder Beginner Contest 414 E] Count A%B=C 题解分享:[蓝桥杯 2025 国 Python A] 杨辉三角 P12876 FiF口语训练破解刷分教程(适用于 Windows) 不要与蠢人辩论 小心网络地雷·续篇 当心网络组织“开往”·续篇 当心网络组织“开往” 小心网络地雷 在 Halo CMS 中通过模板实现随机推荐多篇文章 回应某博客上有关“开往”组织在内部会议上对我的污蔑(上) 再遭 DDoS 攻击:CDN 流量限额拦不住请求计费飙升 2025年团体程序设计天梯赛 - Python 个人赛时暴力题解 网站流量分析工具 Umami 中国大陆合规版发布 把握当下,享受生活 Folo 认证功能反成漏洞?警惕 RSS 订阅源所有权被恶意盗取风险 在 Halo CMS 中通过模板实现随机文章跳转功能 从沉默展柜到时代回响:731部队罪证陈列馆参访手记 脚本分享:CDN 流量触顶后自动切换至 Cloudflare 官方 BUG 快薅!Halo 永久/买断用户可额外获得一份买断许可 老用户专享!已有 1Panel 永久授权/买断许可用户可再领免费买断许可证! 限时特惠!1¥ 立即解锁 1Panel 专业版全功能 61 天 混合云架构下的动态 IPv6 智能加速实践:从家庭网络到全球分发的低成本部署指南 如何用 AI 全方面辅助博客创作 - 从博文之内到博文之外 Random Number Generation and Formatting in Thymeleaf Thymeleaf 随机数生成与格式化详解 列举我维护的项目和发布的软件包 快速部署教程 - 通过 Webhook 触发邮件通知的开源自托管服务 Going Against the Grain - Four Websites That Make Your URL Longer 反其道而行 - 四个让你网址变得更长的网站 2024 年终总结 & 博客一周年 基于 OneBot API 的简易异步 QQ 群批量发消息脚本 如何快速完成中文排版优化 如何给文章分类和打标签 群规之敏感违禁词对抗 一图展示​ ​RSS3 世界 - The Open(RSS3) Universe 开源项目发到 bilibili 后可能获得的 PR C/C++:为什么 a[i][j] 等价于 *(*(a+i)+j) C++ 中快速将字符串大写字母转为小写的方法 Fixing GitHub Actions push to ghcr '403 Forbidden' error Fixing docker pull image "ghcr.io..." Unauthorized error 本站“算法题练习/题解分享”相关文章汇总 不怕流氓多,就怕流氓有文化——站长应该防范的几个问题及对应解决方法分享 题解分享:HRBUST 1132 水数 新手程序员必备的三项技能 如何快速排查插件(模组)的兼容性问题(基于二分法和分治思想) 通过 Umami 最新功能观察定时发布文章的最佳时段 踩坑分享:如何一个人搬运 126.7 斤的书坐动车 两篇文章分享:别像弱智一样提问 & 提问的智慧 论下落式音游/定轨音游中的优质粪铺(文末附铺面推荐) 为什么选择无纸化阅读?为什么买墨水屏电子书?为什么 Kindle“失败”了? 我维护的 Halo 主题,现已发布到 Halo 应用商店! OSU!Standard(osu!std)/OSU!Taiko 转 OSU!Mania 铺面转换器发布 我常用的 OSU!Mania 皮肤分享 电荷守恒辨析:为什么一个离子带多个电荷要乘上所带电荷数而不是除以所带电荷数 注意!align-items: flex-start 会导致 overflow-wrap: break-word 失效 惊人 98 元限定T恤!1Panel, Halo 开发商开启推广积分奖励活动 Minecraft Spigot Bukkit 服务器插件开发 教程收集 中文博客倡议 Windows 10 遇到“只能重装系统”但不想重装的解决方案 Windows 10 文件系统错误 -2144926975 -2147219196 修复 Windows 10 升级 Windows 11 简明教程 CSS 预处理器如何正确的复用样式(stylus 中使用 @extend 继承的坑) 请一定要回复博客下的匿名评论!对于博主和评论者有关匿名评论的倡议 一图解释单一质点运动波动图像和振动图像的关系 解决 Docker pull image "ghcr.io..." Unauthorized error 解决 GitHub Actions push to ghcr '403 Forbidden' error 解决 Umami API 更新延迟问题(如何修改开源项目代码并构建 Docker 镜像-以 Umami 为例) 在国家公祭日自动将网站变灰 中文博客圈列表 解决 Halo CMS 的 Umami Plugin CORS&CSP 跨域报错问题 Windows 创建存储池报错 无法创建池 不支持该请求 (0x00000032) Windows 显示器突然黑白 桌面突然黑白 鼠标和截图还是彩色的 通过指令过滤出正确的公网 IPv6 地址(记一次折腾 IPv6 DDNS) 我的世界免费科技地址 1.7-1.21 网站 Favicon 下载工具发布 键盘 Bios 内可用 系统内无法输入 设备管理器无黄色感叹号 设备管理器 网卡一堆黄色感叹号 例如 WAN, Miniport
Fast Methods to Convert Uppercase Letters to Lowercase in C++
HowieHz · 2024-11-20 · via 皓子的小站
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse") // Enable global common subexpression elimination
#pragma GCC optimize("-fgcse-lm") // Perform load motion during GIMPLE optimization
#pragma GCC optimize("-fipa-sra") // Enable interprocedural scalar replacement of aggregates
#pragma GCC optimize("-ftree-pre") // Enable partial redundancy elimination
#pragma GCC optimize("-ftree-vrp") // Perform value range propagation
#pragma GCC optimize("-fpeephole2") // Enable peephole optimizations after register allocation
#pragma GCC optimize("-ffast-math") // Enable fast math optimizations (less strict IEEE compliance)
#pragma GCC optimize("-fsched-spec") // Allow speculative motion of instructions
#pragma GCC optimize("unroll-loops") // Enable loop unrolling
#pragma GCC optimize("-falign-jumps") // Align branch targets to improve performance
#pragma GCC optimize("-falign-loops") // Align loop entry points
#pragma GCC optimize("-falign-labels") // Align branch labels
#pragma GCC optimize("-fdevirtualize") // Enable devirtualization optimizations
#pragma GCC optimize("-fcaller-saves") // Save caller-saved registers around function calls
#pragma GCC optimize("-fcrossjumping") // Merge identical code sequences at jumps
#pragma GCC optimize("-fthread-jumps") // Perform thread jump optimizations
#pragma GCC optimize("-funroll-loops") // Perform aggressive loop unrolling
#pragma GCC optimize("-fwhole-program") // Perform whole-program optimizations
#pragma GCC optimize("-freorder-blocks") // Reorder basic blocks to improve branch prediction
#pragma GCC optimize("-fschedule-insns") // Reschedule instructions to reduce pipeline stalls
#pragma GCC optimize("inline-functions") // Inline functions aggressively
#pragma GCC optimize("-ftree-tail-merge") // Merge identical code at the ends of functions
#pragma GCC optimize("-fschedule-insns2") // Further reschedule instructions after register allocation
#pragma GCC optimize("-fstrict-aliasing") // Enforce strict aliasing rules
#pragma GCC optimize("-fstrict-overflow") // Assume signed arithmetic overflow does not occur
#pragma GCC optimize("-falign-functions") // Align function entry points
#pragma GCC optimize("-fcse-skip-blocks") // Perform CSE (common subexpression elimination) across blocks
#pragma GCC optimize("-fcse-follow-jumps") // Perform CSE following jumps
#pragma GCC optimize("-fsched-interblock") // Perform instruction scheduling across basic blocks
#pragma GCC optimize("-fpartial-inlining") // Allow partial inlining of functions
#pragma GCC optimize("no-stack-protector") // Disable stack protection mechanisms
#pragma GCC optimize("-freorder-functions") // Reorder function layout to improve performance
#pragma GCC optimize("-findirect-inlining") // Perform indirect inlining
#pragma GCC optimize("-fhoist-adjacent-loads") // Hoist adjacent loads
#pragma GCC optimize("-frerun-cse-after-loop") // Re-run common subexpression elimination after loop optimizations
#pragma GCC optimize("inline-small-functions") // Inline very small functions
#pragma GCC optimize("-finline-small-functions") // Inline small functions more aggressively
#pragma GCC optimize("-ftree-switch-conversion") // Optimize switch statements into conditional chains
#pragma GCC optimize("-foptimize-sibling-calls") // Optimize sibling and tail recursive calls
#pragma GCC optimize("-fexpensive-optimizations") // Perform more expensive optimizations
#pragma GCC optimize("-funsafe-loop-optimizations") // Assume loops do not overflow
#pragma GCC optimize("inline-functions-called-once") // Inline functions called only once
#pragma GCC optimize("-fdelete-null-pointer-checks") // Remove redundant null pointer checks

#include <algorithm>  // for std::transform
#include <chrono>     // for performance measurement
#include <cstring>    // for std::strcpy
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

// Define pointers to functions for string conversion
using ptr = string (*)(string);
using ptr_cr = string (*)(const string&);

// Struct to store function pointers and their names
struct func_info {
    ptr func;          // Function pointer
    string name;       // Name of the function
};

struct func_info_cr {
    ptr_cr func;       // Function pointer (const reference version)
    string name;       // Name of the function
};

vector<pair<string, int64_t>> results; // Stores function performance results
map<string, int> winner; // Tracks the number of wins for each function

string strlwr_a_cr(const string& input) {
    string result = input;
    for (size_t i = 0; i < result.size(); ++i) {
        if (result[i] >= 'A' && result[i] <= 'Z') {
            result[i] += 32;
        }
    }
    return result;
}

string strlwr_a(string input) {
    for (size_t i = 0; i < input.size(); ++i) {
        if (input[i] >= 'A' && input[i] <= 'Z') {
            input[i] += 32;
        }
    }
    return input;
}

string strlwr_a_bitwise_operation_cr(const string& input) {
    string result = input;
    for (size_t i = 0; i < result.size(); ++i) {
        if (result[i] >= 'A' && result[i] <= 'Z') {
            result[i] |= 32;
        }
    }
    return result;
}

string strlwr_a_bitwise_operation(string input) {
    for (size_t i = 0; i < input.size(); ++i) {
        if (input[i] >= 'A' && input[i] <= 'Z') {
            input[i] |= 32;
        }
    }
    return input;
}

string strlwr_a_tolower_cr(const string& input) {
    string result = input;
    for (size_t i = 0; i < result.size(); ++i) {
        if (result[i] >= 'A' && result[i] <= 'Z') {
            result[i] = tolower(result[i]);
        }
    }
    return result;
}

string strlwr_a_tolower(string input) {
    for (size_t i = 0; i < input.size(); ++i) {
        if (input[i] >= 'A' && input[i] <= 'Z') {
            input[i] = tolower(input[i]);
        }
    }
    return input;
}

string strlwr_b_cr(const string& input) {
    string result = input;
    // Extra space for null terminator
    char cstr[result.size() + 1];
    strcpy(cstr, result.c_str());
    strlwr(cstr);
    return string(cstr);
}

string strlwr_b(string str) {
    char cstr[str.size()];
    strcpy(cstr, str.c_str());
    strlwr(cstr);
    return string(cstr);
}

string strlwr_b_plus1(string str) {
    // Extra space for null terminator
    char cstr[str.size() + 1];
    strcpy(cstr, str.c_str());
    strlwr(cstr);
    return string(cstr);
}

char cstr_array[100000001];

string strlwr_b_gobal_array_cr(const string& input) {
    string result = input;
    strcpy(cstr_array, result.c_str());
    strlwr(cstr_array);
    return string(cstr_array);
}

string strlwr_b_gobal_array(string str) {
    strcpy(cstr_array, str.c_str());
    strlwr(cstr_array);
    return string(cstr_array);
}

string strlwr_c_cr(const string& input) {
    return string(strlwr((char*)input.c_str()));
}

string strlwr_c(string str) { return string(strlwr((char*)str.c_str())); }

string strlwr_d_cr(const string& input) {
    string result = input;
    std::transform(result.begin(), result.end(), result.begin(), ::tolower);
    return result;
}

string strlwr_d(string str) {
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    return str;
}

string strlwr_e_cr(const string& input) {
    string str = input;
    std::for_each(str.begin(), str.end(), [](char& c) { c = ::tolower(c); });
    return str;
}

string strlwr_e(string str) {
    std::for_each(str.begin(), str.end(), [](char& c) { c = ::tolower(c); });
    return str;
}

string strlwr_f_cr(const string& input) {
    stringstream ss;
    for (char c : input) {
        ss << static_cast<char>(tolower(c));
    }
    return ss.str();
}

string strlwr_f(string str) {
    stringstream ss;
    for (char c : str) {
        ss << static_cast<char>(tolower(c));
    }
    return ss.str();
}

string strlwr_g_cr(const string& input) {
    string str = input;
    for (auto it = str.begin(); it != str.end(); it++) {
        *it = tolower(*it);
    }
    return str;
}

string strlwr_g(string str) {
    for (auto it = str.begin(); it != str.end(); it++) {
        *it = tolower(*it);
    }
    return str;
}

void testfunc(ptr_cr func, const string& func_name, const string& str, int count) {
    // Measure execution time for functions that take `const string&` as input
    auto start = chrono::high_resolution_clock::now();
    for (int i = 0; i < count; ++i) {
        func(str); // Call the function repeatedly
    }
    auto duration = chrono::duration_cast<chrono::microseconds>(
        chrono::high_resolution_clock::now() - start);
    results.push_back({func_name, duration.count()}); // Store the results
}

void testfunc(ptr func, const string& func_name, const string& str, int count) {
    // Measure execution time for functions that take `string` as input
    auto start = chrono::high_resolution_clock::now();
    for (int i = 0; i < count; ++i) {
        func(str); // Call the function repeatedly
    }
    auto duration = chrono::duration_cast<chrono::microseconds>(
        chrono::high_resolution_clock::now() - start);
    results.push_back({func_name, duration.count()}); // Store the results
}

void print_results(int count) {
    // Display performance results in a sorted order
    cout << "Results:" << endl;
    sort(results.begin(), results.end(),
         [](const pair<string, int64_t>& a, const pair<string, int64_t>& b) {
             return a.second < b.second; // Sort by execution time
         });
    for (const auto& result : results) {
        cout << setw(7) << result.second << "ms" // Total time in milliseconds
             << "   avg:" << fixed << setprecision(4)
             << 1.0 * result.second / count // Average time per operation
             << "   " << result.first << endl; // Function name
    }
    auto min_time = min_element(
        results.begin(), results.end(),
        [](const pair<string, int64_t>& a, const pair<string, int64_t>& b) {
            return a.second < b.second;
        });
    winner[min_time->first]++; // Increment the winner counter for the fastest function
    cout << "The fastest function is " << min_time->first << " with time "
         << min_time->second << " ms" << endl;
}

vector<func_info> func_list = {
    // List of functions to test with `string` parameter
    func_info{strlwr_a, "strlwr_a"},
    func_info{strlwr_a_tolower, "strlwr_a_tolower"},
    func_info{strlwr_a_bitwise_operation, "strlwr_a_bitwise_operation"},
    func_info{strlwr_b, "strlwr_b"},
    func_info{strlwr_b_plus1, "strlwr_b_plus1"},
    func_info{strlwr_b_gobal_array, "strlwr_b_gobal_array"},
    func_info{strlwr_c, "strlwr_c"},
    func_info{strlwr_d, "strlwr_d"},
    func_info{strlwr_e, "strlwr_e"},
    func_info{strlwr_f, "strlwr_f"},
    func_info{strlwr_g, "strlwr_g"}};

vector<func_info_cr> func_list_cr = {
    // List of functions to test with `const string&` parameter
    func_info_cr{strlwr_a_cr, "strlwr_a_cr"},
    func_info_cr{strlwr_a_tolower_cr, "strlwr_a_tolower_cr"},
    func_info_cr{strlwr_a_bitwise_operation_cr, "strlwr_a_bitwise_operation_cr"},
    func_info_cr{strlwr_b_cr, "strlwr_b_cr"},
    func_info_cr{strlwr_b_gobal_array_cr, "strlwr_b_gobal_array_cr"},
    func_info_cr{strlwr_c_cr, "strlwr_c_cr"},
    func_info_cr{strlwr_d_cr, "strlwr_d_cr"},
    func_info_cr{strlwr_e_cr, "strlwr_e_cr"},
    func_info_cr{strlwr_f_cr, "strlwr_f_cr"},
    func_info_cr{strlwr_g_cr, "strlwr_g_cr"}};

void test_func_list(const string& str, int count) {
    // Test all functions with the provided string and repeat count
    for (const auto& func : func_list) {
        testfunc(func.func, func.name, str, count);
    }
    for (const auto& func : func_list_cr) {
        testfunc(func.func, func.name, str, count);
    }
    print_results(count); // Print the results
    results.clear(); // Clear results for the next test
    cout << endl;
}

int main() {
    // Run tests with various input strings and repeat counts
    cout << "Test with empty string" << endl;
    test_func_list("", 1000001);

    cout << "Test with single character: H" << endl;
    test_func_list("H", 1000001);

    cout << "Test with two characters: AH" << endl;
    test_func_list("AH", 1000001);

    cout << "Test with three characters: AHA" << endl;
    test_func_list("AHA", 1000001);

    cout << "Test with four characters: HELL" << endl;
    test_func_list("HELL", 1000001);

    cout << "Test with five characters: Hello" << endl;
    test_func_list("Hello", 1000001);

    cout << "Test with special characters: $%^&*" << endl;
    test_func_list("$%^&*", 1000001);

    string long_lower_str(100000, 'a'); // Generate a long string of 'a'
    string long_dash_str(100000, '-'); // Generate a long string of '-'
    cout << "Test with string: string(100000, 'a')" << endl;
    test_func_list(long_lower_str, 101);

    cout << "Test with string: string(100000, '-')" << endl;
    test_func_list(long_dash_str, 101);

    cout << "Test with mixed case: string(100000, 'a') + 'A' + string(100000, 'a')" << endl;
    test_func_list(long_lower_str + "A" + long_lower_str, 101);

    cout << "Test with mixed case: string(100000, '-') + 'A' + string(100000, '-')" << endl;
    test_func_list(long_dash_str + "A" + long_dash_str, 101);

    // Test with normal strings
    cout << "Test with normal string: Hello, World!" << endl;
    test_func_list("Hello, World!", 1000001);

    // Test with long strings
    cout << "Test with long string: string(100000, 'A')" << endl;
    string long_str(100000, 'A');
    test_func_list(long_str, 101);

    // Test with very long strings
    cout << "Test with very long string: string(1000000, 'A')" << endl;
    string very_long_str(1000000, 'A');
    test_func_list(very_long_str, 11);

    // Test with super long strings
    cout << "Test with super long string: string(10000000, 'A')" << endl;
    cout << "Not all functions will be tested due to array size limitations" << endl;
    string super_long_str(100000000, 'A');

    // Remove functions unsuitable for super long strings
    func_list.erase(remove_if(func_list.begin(), func_list.end(),
                              [](const func_info& f) {
                                  return f.name == "strlwr_b" ||
                                         f.name == "strlwr_b_plus1";
                              }),
                    func_list.end());
    func_list_cr.erase(remove_if(func_list_cr.begin(), func_list_cr.end(),
                                 [](const func_info_cr& f) {
                                     return f.name == "strlwr_b_cr";
                                 }),
                       func_list_cr.end());
    test_func_list(super_long_str, 1);

    // Print the winner count for each function
    cout << endl << "Winner:" << endl;
    for (const auto& w : winner) {
        cout << w.first << ": " << w.second << endl;
    }

    return 0;
}