I saw a question on Zhihu today about the performance comparison between <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;font-size: 14px;">Go</span>
and <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;font-size: 14px;">Java</span>
. This kind of question There is usually only one ending, and that is endless debate. Ten years from now, if these two languages are still alive, this may still be a hot issue:
Put aside the application Talking about performance in scenarios is just a joke
At present, I mainly use Java and Go, and the direction is big data. First, let me talk about my views:
Most languages have areas in which they are good at, and their existence is reasonable:
<span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;">PHP</span>
Good at Building low-cost WEB is also the best language in the world<span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;">c</span>
Good at operating systems and embedded<span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;">Go</span>
Naturally high concurrency attribute##R<span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;"></span>
’s scientific calculations and statistics are unparalleled<span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;">Python</span>
is the leader in the field of AI<span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;"> Java</span>
Industrial-grade application services and Android (the old gangster who has long dominated the TIOBE list)##Benchmarks<span style="color: rgb(74, 74, 74);box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;"></span> The test data can certainly explain some problems, but this test environment and method are still not grounded enough. It is rare to encounter similar cases, and it will not be mentioned in actual use. Because of the gap of a few milliseconds, I changed the language and refactored the project.
## Hot Code
<span style="color: rgb(74, 74, 74);font-size: 16px;box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;"> This concept is very important. Some code snippets will hit once a month, then it will not How much extreme optimization is needed. </span>
28
<span style="color: rgb(74, 74, 74);font-size: 16px;box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;"> Rule, spend 80% of your energy on the important 20% of the code, people My energy is limited, and there are still many beautiful things in the world, such as writing original articles to share with everyone (manual wink). </span>
-
##Talkischeap.Showme the code.
Summary of advantages and disadvantagesBased on my experience, the current programming level of most people , it’s not my turn to talk about the performance of the language itself. If you are not, then please add me on WeChat and let me fly. <span style="color: rgb(74, 74, 74);font-size: 16px;box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;"></span>
The current problem with JAVA is not performance, because the code automatically optimized by JIT is already comparable to C.
The problem with JAVA is that in real actual projects, there are too many third-party dependencies, a bloated architecture, and over-design. At this time, it is hard to say who will win.
I personally think that because go basically only needs the standard library, the performance in actual projects is better than JAVA (Go’s coroutine is essentially an asynchronous IO model, Go language: everything is asynchronous ), in addition, resource usage is also a part of performance. Obviously go has smaller memory usage and relatively low CPU consumption.
Go on the benchmark game runs faster than Java in most scenarios, and the memory consumption is 1/3 of Java;
Let’s list the shortcomings of Go:
It’s a bit anti-programmer syntax
No generics
The data structures in the standard library are far less rich than Java
Dependency management is useless
If channel is used improperly, it is very easy to deadlock
Loop import is not allowed during compilation
Many package names will conflict with custom variable names during coding
There are many libraries that we take for granted in Java, but we find that we have to reinvent the wheel in Go
The go get command will clone the entire git Warehouse, including historical commit
The standard library does not provide a routine pool
There is no ready-made one Future mechanism, you have to implement it yourself through channel
Those are the things that come to mind for the time being; of course all of these can be solved
Disadvantages of Java:
Those are the things that come to mind for the time being; of course, the advantages of Java far outweigh these shortcomings, otherwise it would not be ranked first in the TIOBE programming language rankings all year round
Lack of language expression skills (a down-to-earth term is "stinky and long")
High memory and CPU consumption
When the heap memory is large, the garbage collector needs in-depth tuning to obtain satisfactory recycling effects; however, in some cases In scenarios with high real-time requirements, gc may simply have no solution. Once full gc is triggered, it will be hell
The program needs to be warmed up
The JDK is huge, and the springboot jar package is huge (the problem is most prominent under the microservice architecture)
##Spring FamilyBucket is getting heavier and heavier (for Spring, it is enough for you to do IoC AOP), resulting in poor performance of applications using FamilyBucket (please refer to the position of spring in TechEmpower Round 14), but it is still sufficient
Because there are too many mature frameworks and libraries, many people are biased when they get started, thinking that programming is just adjusting APIs and using frameworks, but they know little about the principles
The above is the detailed content of Go's performance is not as good as Java's?. For more information, please follow other related articles on the PHP Chinese website!

Golang is suitable for rapid development and concurrent programming, while C is more suitable for projects that require extreme performance and underlying control. 1) Golang's concurrency model simplifies concurrency programming through goroutine and channel. 2) C's template programming provides generic code and performance optimization. 3) Golang's garbage collection is convenient but may affect performance. C's memory management is complex but the control is fine.

Goimpactsdevelopmentpositivelythroughspeed,efficiency,andsimplicity.1)Speed:Gocompilesquicklyandrunsefficiently,idealforlargeprojects.2)Efficiency:Itscomprehensivestandardlibraryreducesexternaldependencies,enhancingdevelopmentefficiency.3)Simplicity:

C is more suitable for scenarios where direct control of hardware resources and high performance optimization is required, while Golang is more suitable for scenarios where rapid development and high concurrency processing are required. 1.C's advantage lies in its close to hardware characteristics and high optimization capabilities, which are suitable for high-performance needs such as game development. 2.Golang's advantage lies in its concise syntax and natural concurrency support, which is suitable for high concurrency service development.

Golang excels in practical applications and is known for its simplicity, efficiency and concurrency. 1) Concurrent programming is implemented through Goroutines and Channels, 2) Flexible code is written using interfaces and polymorphisms, 3) Simplify network programming with net/http packages, 4) Build efficient concurrent crawlers, 5) Debugging and optimizing through tools and best practices.

The core features of Go include garbage collection, static linking and concurrency support. 1. The concurrency model of Go language realizes efficient concurrent programming through goroutine and channel. 2. Interfaces and polymorphisms are implemented through interface methods, so that different types can be processed in a unified manner. 3. The basic usage demonstrates the efficiency of function definition and call. 4. In advanced usage, slices provide powerful functions of dynamic resizing. 5. Common errors such as race conditions can be detected and resolved through getest-race. 6. Performance optimization Reuse objects through sync.Pool to reduce garbage collection pressure.

Go language performs well in building efficient and scalable systems. Its advantages include: 1. High performance: compiled into machine code, fast running speed; 2. Concurrent programming: simplify multitasking through goroutines and channels; 3. Simplicity: concise syntax, reducing learning and maintenance costs; 4. Cross-platform: supports cross-platform compilation, easy deployment.

Confused about the sorting of SQL query results. In the process of learning SQL, you often encounter some confusing problems. Recently, the author is reading "MICK-SQL Basics"...

The relationship between technology stack convergence and technology selection In software development, the selection and management of technology stacks are a very critical issue. Recently, some readers have proposed...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment