- ASP.NET Core 2 High Performance(Second Edition)
- James Singleton
- 560字
- 2021-07-08 09:39:01
Language considerations
People often focus on the speed of the programming language that is used. However, this often misses the point. This is a very simplistic view that glosses over the nuances of technology choices. It is easy to write slow software in any language.
With the huge amounts of processing speed that is available today, relatively slow interpreted languages can often be fast enough and the increase in development speed is worth it. It is important to understand the arguments and the trade-offs involved, even if after reading this book you decide to use C# and .NET.
The way to write the fastest software is to get down to the metal and write in assembly language (or even machine code). This is complex to develop, debug, and test, which requires expert knowledge. We rarely do this these days, except for very niche applications (such as virtual reality games, scientific data crunching, and sometimes embedded devices) and usually only for a tiny part of the software.
A higher level of abstraction is writing in a language such as Go, C, or C++ and compiling the code to run on the machine. This is still popular for games and other performance-sensitive applications, but you often have to manage your own memory (which can cause memory leaks or security issues, such as buffer overflows). The .NET Native project, which is currently in development, promises a lot of performance benefits of this ahead-of-time compilation without the downsides, similar to Go.
A level above is software that compiles to a hardware-agnostic Intermediate Language (IL) or bytecode and runs on a Virtual Machine (VM). Examples of this are Java, Scala, Clojure (bytecode on the Java VM), and, of course, C# (IL on the Common Language Runtime). Memory management is normally taken care of, and there is usually a Garbage Collector (GC) to tidy up unused references (Go and the .NET Native CoreRT also have a GC). These applications can run on multiple platforms, and they are safer. However, you can still get near native performance in terms of execution speed, although startup speed can suffer.
Above these are interpreted languages, such as Ruby, Python, and JavaScript. These languages are not usually compiled, and they are run line by line by an interpreter. They usually run slower than a compiled language, but this is often not a problem. A more serious concern is catching bugs when using dynamic typing. You won't be able to see an error until you encounter it, whereas many errors can be caught at compile time when using statically typed languages.
It is best to avoid generic advice. You may hear an argument against using Ruby on Rails, citing the example of Twitter having to migrate to Java for performance reasons. This may well not be a problem for your application, and indeed, having the popularity of Twitter would be a nice problem to have. A bigger concern when running Rails may be the large memory footprint, making it expensive to run on cloud instances.
This section is only to give you a taste, and the main lesson is that normally language doesn't matter. It is not usually the language that makes a program slow, it's poor design choices. C# offers a nice balance between speed and flexibility that makes it suitable for a wide range of applications, especially server-side web applications.
- Python爬蟲開發:從入門到實戰(微課版)
- DevOps入門與實踐
- OpenCV 3和Qt5計算機視覺應用開發
- 微信公眾平臺開發:從零基礎到ThinkPHP5高性能框架實踐
- 學Python也可以這么有趣
- Ext JS 4 Web Application Development Cookbook
- Solr Cookbook(Third Edition)
- R用戶Python學習指南:數據科學方法
- Android Studio Cookbook
- Using Yocto Project with BeagleBone Black
- Java編程指南:語法基礎、面向對象、函數式編程與項目實戰
- 從零開始學UI設計·基礎篇
- Instant AppFog
- Instant SQL Server Analysis Services 2012 Cube Security
- 深入理解C++11:C++11新特性解析與應用