In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to test the performance of go language". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
We can write three types of tests for Go programs: functional tests, benchmarks, and performance tests.
Conventions for test files
The main name of the test file should be preceded by the main name of the file under test and suffixed with_test. Example: The test file name for demo.go should be demo_test.go.
In general, a test file only tests one source file, demo_test.go only tests demo.go files.
The test file and the file under test should be placed in the same code package
Definition of the name and signature of a function
For functional test functions, the name must be prefixed with Test, and there should be only one parameter declaration of type *testing.T in the parameter list.
For performance test functions, the name must be prefixed with Benchmark, and the unique parameter must be of type *testing.B.
For example test functions, the name must be prefixed with Example, and there is no mandatory parameter list for the function.
package demoimport ( "fmt" "testing")//functional test func TestMethod(t *testing.T) { fmt.Println("function test")}//benchmark func BenchmarkMethod(b *testing.B) { fmt.Println("benchmark test")}//Performance test func Exampleethod (t *testing.T) { fmt.Println("example test")}func Method(t *testing.T) { fmt.Println("Method")}go test command
The go test command will automatically read the file named *_test.go under the source directory, generate and run the executable file for testing.
Running the go test command will run the test code as specified;
The go test command builds, executes, cleans up temporary files, and prints test results for each code package under test.
Command:
go test demo #go test [Contents]
Here whether read cache does not affect our test results, if you want to clear cache can be executed: go clean -cache
Performance test #format: go test -bench=. -run=^$ [catalog]go test -bench=. -run=^$ demo
-bench= performance test to be performed
. Performance test function with arbitrary name required to be executed (rule compliant)
-run=^$Test function of what functions need to be performed
^$Executes only function test functions with empty names (does not execute any function)
Output content:
function test benchmark test goos: windows goarch: amd64 pkg: demo BenchmarkMethod-8 benchmark test benchmark test benchmark test benchmark test benchmark test 2000000000 0.00 ns/op PASS ok demo 0.262s
"Go language how to perform performance testing" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.