In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What are the Julia performance analysis tools, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Brief introduction of performance Analysis tools
One of the main reasons for learning the Julia language is its efficiency, so how can we know the performance of the code we write? Today we'll take a look at some tools for performance analysis of Julia code.
# take a look at the Julia version first
Versioninfo ()
Julia Version 1.0.5
Commit 3af96bcefc (2019-09-09 19:06 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel (R) Core (TM) i7-7800X CPU @ 3.50GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
JULIA_PARDISO = / home/ubuntu/Pardiso
1 define test function
Let's first define a function, the probability density function of the Gaussian distribution, to test the following performance analysis code.
Constant Base.@irrational sqrt2 π 2.5066282746310005024 sqrt (big (π) * 2.0)
Base.@irrational invsqrt2 π 0.3989422804014326779 inv (big (sqrt2 π))
Normal curve function norm_pdf (x::Array {Float64,1}; μ = 0.0, σ = 1.0)
Exp. (- (x.- μ). ^ 2Universe 2 σ) * invsqrt 2π / σ
End
Norm_pdf (generic function with 1 method)
X = 10rand (10000)-5
A = norm_pdf (x)
Min (a...), max (a...)
(1.4871534608097617e-6, 0.3989417980536153)
2 Macro # `@ time` for performance analysis is the easiest way to view the run time
@ time norm_pdf (x)
0.000411 seconds (17 allocations: 469.406 KiB)
Julia is a Just-In-Time (JIT) compiled language, that is, each statement is run using compiled machine code.
This means that if you measure the running time of Julia code for the first time, it actually includes the time it takes to compile the code (and memory usage).
Therefore, to see the running time of a piece of Julia code, you should run the code at least once before using the following analysis code.
# Julia compiles the code the first time it is run, which takes longer, so timing starts from the second time
# for example, the time to run for the first time is
0.034050 seconds (72.64k allocations: 3.861 MiB)
# the time required for the second run is
0.000441 seconds (19 allocations: 469.406 KiB)
The memory allocation of # `@ timev` is higher than that of @ time.
@ timev norm_pdf (x)
0.000398 seconds (17 allocations: 469.406 KiB)
Elapsed time (ns): 398107
Bytes allocated: 480672
Pool allocs: 11
Malloc () calls: 6
# `@ elapsed` returns the run time directly.
T = @ elapsed norm_pdf (x)
0.000442561
# use BenchmarkTools packages to display more information.
Using BenchmarkTools
@ benchmark norm_pdf (x)
BenchmarkTools.Trial:
Memory estimate: 469.25 KiB
Allocs estimate: 13
-
Minimum time: 117.534 μ s (0.005% GC)
Median time: 120.906 μ s (0.005% GC)
Mean time: 134.234 μ s (9.14% GC)
Maximum time: 40.077 ms (99.66% GC)
-
Samples: 10000
Evals/sample: 1
# @ btime returns the minimum time and memory allocation.
@ btime norm_pdf (x)
118.484 μ s (13 allocations: 469.25 KiB)
# @ elapsed returns the minimum time in seconds.
@ belapsed norm_pdf (x)
0.000118526
Well, we will often use these tools when writing code in the future, such as BenchmarkTools, and check the performance of our code from time to time for comparison or improvement.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.