当前位置:网站首页>Why does the std:: string operation perform poorly- Why do std::string operations perform poorly?
Why does the std:: string operation perform poorly- Why do std::string operations perform poorly?
2022-07-03 16:09:00 【Zafo】
problem :
I made a test to compare string operations in several languages for choosing a language for the server-side application. I did a test to compare string operations in several languages , To choose a language for the server-side application .The results seemed normal until I finally tried C++, which surprised me a lot. The result seems normal , Until I finally tried C++, This surprised me very much .So I wonder if I had missed any optimization and come here for help. So I want to know if I missed any optimizations and come here for help .
The test are mainly intensive string operations, including concatenate and searching. The tests are mainly intensive string operations , Including connection and search .The test is performed on Ubuntu 11.10 amd64, with GCC's version 4.6.1. Test in Ubuntu 11.10 amd64 On the implementation ,GCC Version is 4.6.1.The machine is Dell Optiplex 960, with 4G RAM, and Quad-core CPU. The machine is Dell Optiplex 960,4G Memory , Tetranuclear CPU.
in Python (2.7.2): stay Python (2.7.2) in :
def test(): x = "" limit = 102 * 1024 while len(x) < limit: x += "X" if x.find("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0) > 0: print("Oh my god, this is impossible!") print("x's length is : %d" % len(x))test()which gives result: This gives the result :
x's length is : 104448real 0m8.799suser 0m8.769ssys 0m0.008sin Java (OpenJDK-7): stay Java (OpenJDK-7) in :
public class test { public static void main(String[] args) { int x = 0; int limit = 102 * 1024; String s=""; for (; s.length() < limit;) { s += "X"; if (s.indexOf("ABCDEFGHIJKLMNOPQRSTUVWXYZ") > 0) System.out.printf("Find!\n"); } System.out.printf("x's length = %d\n", s.length()); }}which gives result: This gives the result :
x's length = 104448real 0m50.436suser 0m50.431ssys 0m0.488sin Javascript (Nodejs 0.6.3) stay Javascript (Nodejs 0.6.3)
function test(){ var x = ""; var limit = 102 * 1024; while (x.length < limit) { x += "X"; if (x.indexOf("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0) > 0) console.log("OK"); } console.log("x's length = " + x.length);}();which gives result: This gives the result :
x's length = 104448real 0m3.115suser 0m3.084ssys 0m0.048sin C++ (g++ -Ofast) stay C++ (g++ -Ofast)
It's not surprising that Nodejs performas better than Python or Java.Nodejs Better performance than Python or Java It's not surprising .But I expected libstdc++ would give much better performance than Nodejs, whose result really suprised me. But I expect libstdc++ Will provide more than Nodejs Better performance , Its result really surprised me .
#include <iostream>#include <string>using namespace std;void test(){ int x = 0; int limit = 102 * 1024; string s(""); for (; s.size() < limit;) { s += "X"; if (s.find("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0) != string::npos) cout << "Find!" << endl; } cout << "x's length = " << s.size() << endl;}int main(){ test();}which gives result: This gives the result :
x length = 104448real 0m5.905suser 0m5.900ssys 0m0.000sBrief Summary Brief summary
OK, now let's see the summary: well , Now let's look at the summary :
- javascript on Nodejs(V8): 3.1sNodejs(V8) Upper javascript:3.1s
- Python on CPython 2.7.2 : 8.8sCPython 2.7.2 Upper Python:8.8s
- C++ with libstdc++: 5.9s with libstdc++ Of C++:5.9 second
- Java on OpenJDK 7: 50.4sOpenJDK 7 Upper Java:50.4 second
Surprisingly! It's amazing !I tried "-O2, -O3" in C++ but noting helped. I am here C++ I tried “-O2,-O3”, But it helps to notice .C++ seems about only 50% performance of javascript in V8, and even poor than CPython.C++ stay V8 There seems to be only javascript Of 50% performance , Even better than CPython Still bad .Could anyone explain to me if I had missed some optimization in GCC or is this just the case? Can someone explain to me if I missed GCC Some optimizations in , Or just this situation ?Thank you a lot. Thank you very much .
Solution :
Reference resources : https://stackoom.com/en/question/Yrot边栏推荐
- First!! Is lancet hungry? Official documents
- Microservice - Nacos registration center and configuration center
- Effect of ARP package on FTP dump under vxworks-6.6 system
- [list to map] collectors Tomap syntax sharing (case practice)
- 无心剑中译泰戈尔《漂鸟集(1~10)》
- Function introduction of JMeter thread group
- 请做好3年内随时失业的准备?
- How can technology managers quickly improve leadership?
- 【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
- Persisting in output requires continuous learning
猜你喜欢

How to use AAB to APK and APK to AAB of Google play apps on the shelves

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

MongoDB 的安装和基本操作

Reading notes of "micro service design" (Part 2)

使用AUR下载并安装常用程序

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)

The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)

Introduction series of software reverse cracking (1) - common configurations and function windows of xdbg32/64

关于网页中的文本选择以及统计选中文本长度

Microservices Seata distributed transactions
随机推荐
Getting started with Message Oriented Middleware
Client does not support authentication protocol requested by server; consider upgrading MySQL client
Reading notes of "micro service design" (Part 2)
Nine ways to define methods in scala- Nine ways to define a method in Scala?
Mongodb installation and basic operation
WinDbg analysis dump file
深度学习之三维重建
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
MB10M-ASEMI整流桥MB10M
Batch files: list all files in a directory with relative paths - batch files: list all files in a directory with relative paths
Persisting in output requires continuous learning
Mixlab编辑团队招募队友啦~~
Vs2017 is driven by IP debugging (dual machine debugging)
Microservice API gateway zuul
The difference between mutually exclusive objects and critical areas
用通达信炒股开户安全吗?
坚持输出需要不断学习
潘多拉 IOT 开发板学习(HAL 库)—— 实验5 外部中断实验(学习笔记)
Remote file contains actual operation
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)