Sign in Join
Wiki copytemporary

Improving language shootout results: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## About
22
33The computer language shootout (https://benchmarksgame-team.pages.debian.net/benchmarksgame/) is a realistically flawed benchmarking system which compares many languages on a somewhat unequal basis. See the linked page for more info.
44
55## Goals
66
77Our goals are to be on the highest possible positions. The requirements to reach them can be categorized into two.
88
991: Optimizations on the assembler level. (core devel work)
1010
11112: Optimizations of the benchmarks. (junior devel work)
1212
1313## Way to go
1414
1515It was decided that to keep memory requirements low it's best to use val() and str() and never include SysUtils unless really required.
1616
1717Use of inline and records instead of classes can also improve performance considerably, but additional testing and comparing with C and other languages should be the main factor. Special note: inlining of recursive functions is possible and sometimes increases speed.
1818
1919Another thing to use is {\$implicitexceptions off} to keep rtl hindering speed. Dropping down to pchar level in tight loops can be beneficial. Use also only native sized integers and floats if possible.
2020
2121## Benchmarks notes
2222
2323### SSE2 and comparions
2424
2525Consider the following code compiled with -Cfsse2:
2626
2727``` pascal
2828const
2929 limit=4.0;
3030var
3131 x : double;
3232begin
3333 x := 1.73;
3434 if x < limit then
3535 x := x + x;
3636end.
3737```
3838
3939For the condition **x\<limit**, no sse2 code will be generated, because the compiler assumes the const is an extended and therefore needs to perform the comparison with the x87 FPU unit.
4040
4141``` pascal
4242const
4343 limit = double(4.0);
4444```
4545
4646... also doesn't work. However
4747
4848``` pascal
4949const
5050 limit: double = double(4.0);
5151```
5252
5353does.
5454
5555### Binary trees
5656
57-<s>The [binary trees benchmark](https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/binarytrees.html) can be improved using a TNonFreePooledMemoryManager available in fpc 2.1.1. That way the allocation of nodes occurs in blocks and all de-allocation happens all at once for all nodes of the tree. Look for an example [here](http://www.hu.freepascal.org/fpcircbot/cgipastebin?msgid=126). Such an allocator probably won't be allowed though.</s>
57+The [binary trees benchmark](https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/binarytrees.html) can be improved using a TNonFreePooledMemoryManager available in fpc 2.1.1. That way the allocation of nodes occurs in blocks and all de-allocation happens all at once for all nodes of the tree. Look for an example [here](http://www.hu.freepascal.org/fpcircbot/cgipastebin?msgid=126). Such an allocator probably won't be allowed though.
5858
5959FPC is currently in first place for this benchmark, and indeed TNonFreePooledMemoryManager (plus PasMP) were what did the trick.
6060
6161### Mandelbrot
6262
63-<s>The [mandelbrot benchmark](https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/mandelbrot-fpascal-8.html) can be improved with fpc 2.1.1 using the sse2 instructions. Note that sse2 instructions are volatile and the results of a calculation will be put back on the stack, if the same body contains a procedure call. Therefore, a sse2 calculation needs to be moved to a separate (nested) procedure. The mandelbrot benchmark would probably benefit from [[Single assignment|SSA]] in loops, because without it calculations are performed in a scratch register and the result moved to the final register. SSA will prevent this. At the moment fpc 2.1.1 supports SSA only in simple linear flow control without loops and branches.
63+The [mandelbrot benchmark](https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/mandelbrot-fpascal-8.html) can be improved with fpc 2.1.1 using the sse2 instructions. Note that sse2 instructions are volatile and the results of a calculation will be put back on the stack, if the same body contains a procedure call. Therefore, a sse2 calculation needs to be moved to a separate (nested) procedure. The mandelbrot benchmark would probably benefit from [[Single assignment|SSA]] in loops, because without it calculations are performed in a scratch register and the result moved to the final register. SSA will prevent this. At the moment fpc 2.1.1 supports SSA only in simple linear flow control without loops and branches.
6464
65-The latest versions of the competition gain a lot (nearly a factor of 2) by using 128 bit xmm registers for cr, ci, tr, and ti and instructions to do 2 calculations at the same time. I do not see a way to do this with fpc. Please prove me wrong :-)</s>
65+The latest versions of the competition gain a lot (nearly a factor of 2) by using 128 bit xmm registers for cr, ci, tr, and ti and instructions to do 2 calculations at the same time. I do not see a way to do this with fpc. Please prove me wrong :-)
6666
6767FPC's score in this benchmark is currently much better than it was previously (formerly 22.69 seconds, currently 8.52 seconds). Optimization improvements in FPC 3.2.0 versus the current 3.0.4 being used are likely to improve the time even further.
6868
6969### N-body
7070
71-<s>The [n-body benchmark](https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/nbody.html) can be improved with fpc 2.1.1 using the sse2 instructions and factoring out common factors. Compiling with -Cfsse2 and fpc 2.0.4 gives an internal error.</s>
71+The [n-body benchmark](https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/nbody.html) can be improved with fpc 2.1.1 using the sse2 instructions and factoring out common factors. Compiling with -Cfsse2 and fpc 2.0.4 gives an internal error.
7272
7373FPC 2.1.1 is now very outdated and SSE2 works just fine, but this benchmark still needs improvement in general.
7474
7575---
7676*From the Free Pascal wiki, page "Improving language shootout results", as it stood on 2020-03-03 after a change by BenGrasset, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
7777Category: Promotion

Back to history