且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#或C ++中的Web服务器逻辑

更新时间:2023-11-04 22:56:10

忘记C ++,并使用C#进行ASP.NET.性能差异在很大程度上可以忽略不计. ASP.NET和C#设计为可以协同工作,因此使用它们可以缩短您的开发时间. ASP.NET网站 [ ^ ].
Forget C++, and go for ASP.NET with C#; the difference in performance will be largely negligible. ASP.NET and C# have been designed to work together so your development time will be shortened by using them. There are plenty of samples on the ASP.NET web site[^].


互联网上散布着一些基准,似乎表明C ++是一种速度更快的语言因为它比其他任何高级语言(如C#)都更接近内核.但是这些基准非常有限,因为它们会遇到一系列小的重复性问题,这些问题似乎需要大量计算,并且除非您要构建科学或数学计算系统或某种类型的重数据系统(例如Facebook),您将不需要高性能,因为它不会被充分利用.

话虽这么说,出于您的目的,即构建一个服务器端程序,该程序将根据请求明确地回显JSON字符串,因此C#的性能几乎可以与C ++相提并论.与IIS一起运行的ASP.NET引擎使用以低级C编写的本机API,这些API已针对Web服务器AFAIK进行了优化.但是话又说回来,每个用例都是不同的,并且每种技术都比其他问题更适合一组问题.

我的建议是从小规模开始,然后用C#构建另一个2,另一个使用C ++,并在一段时间内自己分析性能.最后,根据您的长期使用策略,从顶部选择一个.

我将很高兴得到纠正或补充. :)
There are benchmarks strewn all over the internet that seem to suggest that C++ is a much faster language simply because its much closer to the kernel than any other high level languages like C#. But these benchmarks are quite limited, in that, they are run over a small repetitive set of problems that seem to be computation intensive and unless you are building a scientific or mathematical computation system or heavy data system of some kind (like Facebook does), you won''t need that high performance because it won''t be utilised fully.

That being said, for your purpose which is building a server side program that will plainly echo a JSON string based on a request, C# will give almost comparable performance to C++. ASP.NET engine that runs with IIS uses native APIs written in low level C that are quite optimised for web servers AFAIK. But then again, every use case is different and every technology suits one set of problems more than others.

My recommendation is to start small and build 2, one with C# and the other with C++ and analyse the performance yourself over a period of time. At the end of it and based on your long term usage strategy, pick one that comes out at the top.

I will be glad to be corrected or added to. :)