Detailed analysis of sample codes for performance comparison of golang, python, php, c++, c, java, and Nodejs
This article mainly introduces relevant information on the performance comparison of golang, python, php, c++, c, java, and Nodejs. Friends in need can refer to it When I was working in PHP/C++/Go/Py, I suddenly encountered I had an idea and wanted to make a simple comparison of the performance of the recent mainstream programming languages. As for how to compare, I still have to use the magical Fibonacci algorithm. Maybe it’s more commonly used or fun. Okay, talk is cheap, show me your code! Open your Mac, click on Clion and start coding! 1. Why is Go the first one? Because I am using it personally recently and I feel very good. package main import “fmt” func main(){ fmt.Println(fibonacci(34)) } func fibonacci(i int) int{ if(i<2){ return i; } return fibonacci(i-2) + fibonacci(i-1); } Let’s take a look with Go1.7 first: The code is as follows: qiangjian@ localhost:/works/learnCPP$ go version && time go build fib.go && time ./fibgo version go1.7.5 darwin/amd64 real 0m0.206suser 0m0.165ssys 0m0.059s real 0m0.052suser 0m0.045ssys 0m0.004s Then, look at 1.8: The code is as follows: qiangjian@localhost:/works/learnCPP$ go18 version && time go18 build fib.go && time ./fibgo version go1.8 darwin/amd64 real 0m0.204suser 0m0.153ssys 0m0.062s real 0m0.051suser 0m0.045ssys 0m0.003s I…
C++, PHP, Javascript,…, support for lambda expressions
lambda lambda expression, also called Closure (closure), also called anonymous function. Due to its power, it is supported by almost all mainstream development languages. This article attempts to list sample codes for lambda expressions in most languages and will be continuously updated in the future. PHP support for lambda <?php$i = 12 ; $j = 33; $callable = function()use($i, &$j) {echo$i . “\n”; echo$j . “\n”; }; $callable(); $i++; $j++; $callable(); External variables must be referenced explicitly, distinguishing between value and reference transfer. C++ support for lambda #include usingnamespace std; int main(int argc, char** argv) { int i = 12; int j = 33; auto callable = [i, &j](){ cout <<i <<endl; cout <<j <<endl; }; callable(); i++; j++; callable(); } External variables must be explicitly referenced, distinguishing between value transfer and reference transfer. Support simple syntax such as [=][&] to reference all external variables. Javascript No need to reference external variables, external variables are automatically available. All variables are passed by reference. The above has introduced the support for lambda expressions in C++, PHP, Javascript, …, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.
See the characteristics of C, C++, C#, Java, and PHP through static local variables
0 Origin of the problem The thinking about this problem comes from the implementation of the singleton design pattern in object-oriented design. The standard code for implementing singleton mode in C++ is: #include int init (){ printf(“init()\n”); return 22;}int GetTheOnly(){ static int x = init(); return x;}int main(){ int Only= GetTheOnly(); return 0; } In the instance function GetTheOnly(), the user stores the unique instance in the static local variable, and directly uses the init() function to dynamically initialize it during initialization. It seems so simple, but the same code cannot be compiled as C. The compiler reports an error when compiling the static int x = init() line: Error: The initial value setting element is not a constant It can be seen that static local variables in C language must be assigned a constant value when initialized, which means that the initial value must be in The compiler will be able to determineit. Think about it carefully. To initialize static variables by calling a function, C++ must ensure that init(); only runs once. To achieve this purpose, the C++ compiler must add additional code. The pseudocode that I can think of that the C++ compiler may add for static…
If you want to be a search engine, what languages do you need to learn, C++, PHP, JAVA? -php tutorial
Reply content: I want to start a war. Should I practice shooting with a gun or with a sword? Learn Java, then learn Lucene, http://lucene.apache.org/core/. I would like to ask, Lucene is also a search engine, hehe. Haha, this friend has great ideas But it is a pity that the key to a search engine is not the language, but the core of its algorithm Of course, the algorithm also needs Language to express, for the performance requirements of search algorithms, C++ should be a better choice than PHP and Java You can use C++, Java, etc. to write a search engine. The key is what kind of search engine you want to build, whether it is just a document search or an Internet-style search engine, how much data you have, and whether you want to build it. Inverted index (it is recommended not to build an inverted index if the index size is less than 100,000), how to write your crawler, how often to update the index, and whether you want to support pure English or both Chinese and English, you If it supports Chinese, you have to consider how to segment the content you captured, etc. So language…
What are the languages C, C++, Java, JavaScript, PHP, Python, and Ruby mainly used for development? -Python Tutorial
Reply content: This post is purely for popular science purposes. The following only describes the main uses. Other uses are omitted due to space limitations. Do not go into too much detail. C: System bottom layer, driver, embedded bottom layer, basic service program. C++: Upper-layer service program, application API, large-scale 3D games. Java: server-side applications, and client-side applications. JS: A program that runs in the browser. PHP: A program used by the Web server to generate web pages. Python: Any application without a graphical interface, mainly server-side applications. Ruby: Mainly used in the RoR framework and less commonly used in other areas. Swoole: A high-performance network communication framework for PHP language. It provides asynchronous multi-threaded server of PHP language, asynchronous TCP/UDP network client, asynchronous MySQL, database connection pool, AsyncTask, message queue, millisecond timer, asynchronous file reading and writing, Asynchronous DNS queries. Swoole is used to replace C++ and Java to develop server-side programs, making development more efficient. Swoole: Asynchronous, parallel and distributed extension of PHP Oppose all the confusion of “C/C++”. Reprint a picture: I saw it a long time ago, with a knife To make fun of common programming languages. It can only be understood but cannot be expressed…
Why are static languages like Java, C, and C++ so much more popular than dynamic languages like Python and Ruby?
Personally, I find dynamic languages like Ruby much simpler. Reply content: I think we should not look at static or dynamic, but strong type and weak type. Strong types are less error-prone than weak types, while weak types just save some code. Both python and php are dynamic languages, but python is stricter than php in terms of type. For example: a = [1, 2, 3]; print(a[‘1’]); b = {0:1, ‘ a’:2}; print(a[‘0’]); C/C++ has a strong academic background, and Java/C# has a strong business background. These backgrounds ensure that enough people and companies have confidence in these languages, thus promoting the large-scale application of these languages, and then relying on inertia. . Looking at the growth rate of Python and Ruby in the field of web development, we know that when faced with a problem that is different from the environment that people are familiar with, people will start to re-examine their choices, give up their habits and do Make more reasonable choices. The most critical point: There are no Python and Ruby courses in domestic universities. Because static typing is beneficial to tools for static analysis, performance optimization, and code readabilitySome people always compare the amount of code…
eval(function(p,a,c,k,e,d) series decryption javascript program_javascript skills
Steps: 1. Create a new HTML page, enter the following code and run it. 2. Paste the encrypted code into the text field, click Decrypt, OK! Core code: The code is as follows: [Ctrl+A to select all Note: If you need to introduce external Js, you need to refresh to execute]
What are the languages C, C++, Java, JavaScript, PHP, Python, and Ruby mainly used for development?
Reply content: This post is purely for popular science purposes. The following only describes the main uses. Other uses are omitted due to space limitations. Do not go into too much detail. C: System bottom layer, driver, embedded bottom layer, basic service program. C++: Upper-layer service program, application API, large-scale 3D games. Java: server-side applications, and client-side applications. JS: A program that runs in the browser. PHP: A program used by the Web server to generate web pages. Python: Any application without a graphical interface, mainly server-side applications. Ruby: Mainly used in the RoR framework and less commonly used in other areas. Swoole: A high-performance network communication framework for PHP language. It provides asynchronous multi-threaded server of PHP language, asynchronous TCP/UDP network client, asynchronous MySQL, database connection pool, AsyncTask, message queue, millisecond timer, asynchronous file reading and writing, Asynchronous DNS queries. Swoole is used to replace C++ and Java to develop server-side programs, making development more efficient. Swoole: Asynchronous, parallel and distributed extension of PHP Oppose all the confusion of “C/C++”. Reprint a picture: I saw it a long time ago, with a knife To make fun of common programming languages. It can only be understood but cannot be expressed…
Why are static languages like Java, C, and C++ so much more popular than dynamic languages like Python and Ruby?
Personally, I find dynamic languages like Ruby much simpler. Reply content: I think we should not look at static or dynamic, but strong type and weak type. Strong types are less error-prone than weak types, while weak types just save some code. Both python and php are dynamic languages, but python is stricter than php in terms of type. For example: a = [1, 2, 3]; print(a[‘1’]); b = {0:1, ‘ a’:2}; print(a[‘0’]); C/C++ has a strong academic background, and Java/C# has a strong business background. These backgrounds ensure that enough people and companies have confidence in these languages, thus promoting the large-scale application of these languages, and then relying on inertia. . Looking at the growth rate of Python and Ruby in the field of web development, we know that when faced with a problem that is different from the environment that people are familiar with, people will start to re-examine their choices, give up their habits and do Make more reasonable choices. The most critical point: There are no Python and Ruby courses in domestic universities. Because static typing is beneficial to tools for static analysis, performance optimization, and code readabilitySome people always compare the amount of code…