官术网_书友最值得收藏!

  • Julia High Performance
  • Avik Sengupta
  • 451字
  • 2021-07-16 11:20:43

How fast can Julia be?

The best evidence of Julia's performance claims is when you write your own code. However, we can provide an indication of how fast Julia can be by comparing a similar algorithm over multiple languages.

As an example, let's consider a very simple routine to calculate the power sum for a series, as follows:

How fast can Julia be?

The following code runs this computation in Julia 500 times:

function pisum()
    sum = 0.0
    for j = 1:500
        sum = 0.0
        for k = 1:10000
            sum += 1.0/(k*k)
        end
    end
    sum
end

You will notice that this code contains no type annotations. It should look quite familiar to any modern dynamic language. The same algorithm implemented in C would look something similar to this:

double pisum() {
    double sum = 0.0;
    for (int j=0; j<500; ++j) {
        sum = 0.0;
        for (int k=1; k<=10000; ++k) {
            sum += 1.0/(k*k);
        }
    }
    return sum;
}

Tip

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  • Log in or register to our website using your e-mail address and password
  • Let the mouse pointer hover on the SUPPORT tab at the top
  • Click on Code Downloads & Errata
  • Enter the name of the book in the Search box
  • Select the book for which you're looking to download the code files
  • Choose from the drop-down menu where you purchased this book from
  • Click on Code Download

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

By timing this code, and its re-implementation in many other languages (all of which are available at https://github.com/JuliaLang/julia/tree/master/test/perf/micro), we can note that Julia's performance claims are certainly borne out in this limited test. Julia can perform at a level similar to C and other statically typed and compiled languages.

This is of course a micro benchmark, and should therefore not be extrapolated too much. However, I hope you will agree that it is possible to achieve excellent performance in Julia. The rest of the book will attempt to show how you can achieve performance close to this standard in your code.

How fast can Julia be?
主站蜘蛛池模板: 华坪县| 灵寿县| 达日县| 综艺| 彭水| 郧西县| 凤阳县| 无极县| 舒城县| 澄迈县| 潞城市| 温泉县| 新郑市| 靖远县| 慈利县| 晴隆县| 家居| 兰西县| 招远市| 巧家县| 乌恰县| 商都县| 洛宁县| 佛冈县| 长乐市| 沈丘县| 桂东县| 宜春市| 武夷山市| 清远市| 安达市| 杭锦旗| 大竹县| 固始县| 梅州市| 泗水县| 滦平县| 横山县| 江油市| 尼木县| 江都市|