Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2021-07

How does FPC perform in the FASTEST Computer Language Race

12 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Wayne Sherman

If you are a speed geek, you will probably be interested in this.

What is the FASTEST Computer Language? 45 Languages Tested! (E01) https://www.youtube.com/watch?v=tQtFdsEcK_s

Current standings at the time of this video
Iterations per sec:
Ada: 67
Pascal: 143
Fastest language: 7301
Slowest language: 1

"HD Episode 01: Retired Microsoft engineer Dave Plummer takes you on a guided tour of 45 different computer languages and drag races each against one another using a prime sieve benchmark. From Ada to Zig and everything in between, find out which is fastest and which is slowest."

Github: https://github.com/PlummersSoftwareLLC/Primes

Current Pascal code:
https://github.com/PlummersSoftwareLLC/Primes/tree/drag-race/PrimePascal/solution_1 Current Delphi code:
https://github.com/PlummersSoftwareLLC/Primes/tree/drag-race/PrimeDelphi/solution_1

Pull requests for faster/better implementations:
https://github.com/PlummersSoftwareLLC/Primes/pulls

Related:
https://components4developers.blog/2021/07/04/delphi-sieve-candidates-to-the-fastest-programming-language-contest/

Reply by email

Winfried Bartnick
to Wayne Sherman

Ohh Nooo!

Back in the 80s.

Winni

Wayne Sherman wrote 33 lines
If you are a speed geek, you will probably be interested in this. What is the FASTEST Computer Language? 45 Languages Tested! (E01) https://www.youtube.com/watch?v=tQtFdsEcK_s Current standings at the time of this video Iterations per sec: Ada: 67 Pascal: 143 Fastest language: 7301 Slowest language: 1 "HD Episode 01: Retired Microsoft engineer Dave Plummer takes you on a guided tour of 45 different computer languages and drag races each against one another using a prime sieve benchmark. From Ada to Zig and everything in between, find out which is fastest and which is slowest." Github: https://github.com/PlummersSoftwareLLC/Primes Current Pascal code: https://github.com/PlummersSoftwareLLC/Primes/tree/drag-race/PrimePascal/solution_1 Current Delphi code: https://github.com/PlummersSoftwareLLC/Primes/tree/drag-race/PrimeDelphi/solution_1 Pull requests for faster/better implementations: https://github.com/PlummersSoftwareLLC/Primes/pulls Related: https://components4developers.blog/2021/07/04/delphi-sieve-candidates-to-the-fastest-programming-language-contest/ _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Jonas Maebe
to Ryan Joseph
Ryan Joseph wrote 12 lines
> On Jul 9, 2021, at 11:40 AM, Wayne Sherman via fpc-pascal wrote: > > Current standings at the time of this video > Iterations per sec: > Ada: 67 > Pascal: 143 > Fastest language: 7301 > Slowest language: 1 So Pascal failed pretty bad it looks like. ;)

If the only thing you do all day is run a particular implementation of the sieve of Eratosthenes...

Jonas

Reply by email

Peter
to Ryan Joseph: So Pascal failed pretty bad it looks like. ;) Ryan Joseph
Ryan Joseph wrote 17 lines
> On Jul 9, 2021, at 11:40 AM, Wayne Sherman via fpc-pascal wrote: > > Current standings at the time of this video > Iterations per sec: > Ada: 67 > Pascal: 143 > Fastest language: 7301 > Slowest language: 1 So Pascal failed pretty bad it looks like. ;) Regards, Ryan Joseph _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Looks like its compiled with no optimisations,

|fpc prime ./prime O3 usually makes a big difference. Regards, Peter |

Reply by email

Guillermo
to Wayne Sherman: If you are a speed geek, you will probably be interested in this. What is the FASTEST…

Hi,

I remember years ago a similar test in a web page. Pascal was way low in the list, even below Java and Python! but we (in a forum) found that it wasn't Pascal fault: most versons program were optimised in code while Pascal used brute force (also compiling using -O3 made it way faster than the web proclaimed so we suspect they used -O- or even worse a relic compiler [Turbo Pascal 1?]). Once fixed it was almost unoticeably behind C in both FPC and Delphi (Delphi result was a bit faster).

Anyway I haven't seen the video yet.

Regards,
Guillermo "Ñuño" Martínez

El Fri, 9 Jul 2021 10:40:55 -0700

Wayne Sherman wrote 33 lines
If you are a speed geek, you will probably be interested in this. What is the FASTEST Computer Language? 45 Languages Tested! (E01) https://www.youtube.com/watch?v=tQtFdsEcK_s Current standings at the time of this video Iterations per sec: Ada: 67 Pascal: 143 Fastest language: 7301 Slowest language: 1 "HD Episode 01: Retired Microsoft engineer Dave Plummer takes you on a guided tour of 45 different computer languages and drag races each against one another using a prime sieve benchmark. From Ada to Zig and everything in between, find out which is fastest and which is slowest." Github: https://github.com/PlummersSoftwareLLC/Primes Current Pascal code: https://github.com/PlummersSoftwareLLC/Primes/tree/drag-race/PrimePascal/solution_1 Current Delphi code: https://github.com/PlummersSoftwareLLC/Primes/tree/drag-race/PrimeDelphi/solution_1 Pull requests for faster/better implementations: https://github.com/PlummersSoftwareLLC/Primes/pulls Related: https://components4developers.blog/2021/07/04/delphi-sieve-candidates-to-the-fastest-programming-language-contest/ _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Ryan Joseph
to Guillermo
Show quoted text 12 lines
On Jul 10, 2021, at 4:16 AM, Guillermo via fpc-pascal wrote: Hi, I remember years ago a similar test in a web page. Pascal was way low in the list, even below Java and Python! but we (in a forum) found that it wasn't Pascal fault: most versons program were optimised in code while Pascal used brute force (also compiling using -O3 made it way faster than the web proclaimed so we suspect they used -O- or even worse a relic compiler [Turbo Pascal 1?]). Once fixed it was almost unoticeably behind C in both FPC and Delphi (Delphi result was a bit faster).

Here's the C++ version that won. Looks like the magic comes from constexpr, which I don't understand very well in C++ except that it's a constant expression. Can anyone explain how constexpr works here?

// ---------------------------------------------------------------------------
// PrimeCPP_CONSTEXPR.cpp : Taking advantage of compiler optimizing constants
// ---------------------------------------------------------------------------
#include <chrono>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <thread>
#include <vector>
#include "Sieve.h"
using namespace std;
using namespace std::chrono;
struct RESULTS
{
    unsigned long long upTo;
    int count;
};

constexpr RESULTS resultsDictionary[] = {
{10LL, 4}, // Historical data for validating our results - the number of primes {100LL, 25}, // to be found under some limit, such as 168 primes under 1000 {1000LL, 168},
{10000LL, 1229},
{100000LL, 9592},
{1000000LL, 78498},
{10000000LL, 664579},
};

constexpr int find(const unsigned long long val)
{
for (const auto d : resultsDictionary)
{
if (d.upTo == val)

            return d.count;
    }
    return -1;

}

constexpr int countPrimes(const Sieve &sieve)
{

    return sieve.count();

}

constexpr bool validateResults(const Sieve &sieve)
{
    const auto sieveSize = sieve.size();
    const auto result = find(sieveSize);
    if (-1 == result)
        return false;
    return result == countPrimes(sieve);
}

void printResults(const Sieve &sieve, bool showResults, double duration, int passes, int threads) {

    const auto sieveSize = sieve.size();
    if (showResults)
        printf("2, ");
    int count = (sieveSize >= 2); // Starting count (2 is prime)
    for (int num = 3; num <= sieveSize; num += 2)
    {
        if (sieve.contains(num))
        {
            if (showResults)
                printf("%d, ", num);
            count++;
        }
    }
    if (showResults)
        printf("\n");
    printf("Passes: %d, Time: %lf, Avg: %lf, Limit: %llu, Count1: %d, Count2: %d, Valid: %d\n",
           passes,
           duration,
           duration / passes,
           sieveSize,
           count,
           countPrimes(sieve),
           validateResults(sieve));
    printf("\n");
    printf("flo80_constexpr;%d;%f;%d;algorithm=base,faithful=no,bits=1\n", passes, duration, threads);
}

void run(uint64_t upperLimit, const Sieve &checkSieve, int numberOfThreads = 1, int runtimeSeconds = 5) {

    unsigned int passes = 0;
    printf("Computing primes to %llu on %d thread%s for %d second%s.\n", upperLimit,
           numberOfThreads,
           numberOfThreads == 1 ? "" : "s",
           runtimeSeconds,
           runtimeSeconds == 1 ? "" : "s");
    const auto tStart = steady_clock::now();
    while (duration_cast<seconds>(steady_clock::now() - tStart).count() < runtimeSeconds)
    {
        vector<thread> threadPool;
        for (unsigned int i = 0; i < numberOfThreads; i++)
        {
            threadPool.push_back(thread([upperLimit]
                                        {
                                            auto sieve = Sieve(upperLimit);
                                            sieve.runSieve();
                                        }));
        }
        for (auto &th : threadPool)
            th.join();
        passes += numberOfThreads;
    }
    const auto tEnd = steady_clock::now();
    printResults(checkSieve, false, duration_cast<microseconds>(tEnd - tStart).count() / 1000000.0, passes, numberOfThreads);
}
int main(int argc, char **argv)
{
    uint64_t upperLimit = 1'000'000L;
    constexpr int runtimeSeconds = 5;
    if (argc > 1)
    {
        upperLimit = std::max((uint64_t)atoll(argv[argc - 1]), (uint64_t)1);
        assert(upperLimit < Sieve::maxSize);
    }
    auto checkSieve = Sieve(upperLimit);
    checkSieve.runSieve();
    const auto result = validateResults(checkSieve) ? checkSieve.count() : 0;
    const auto numberOfThreads = thread::hardware_concurrency();
    thread::hardware_concurrency();
    run(upperLimit, checkSieve, numberOfThreads, runtimeSeconds);
    run(upperLimit, checkSieve, 1, runtimeSeconds);
    return result;
}

Regards,
Ryan Joseph

Reply by email

Jonas Maebe
to Ryan Joseph
Ryan Joseph wrote
Here's the C++ version that won. Looks like the magic comes from constexpr, which I don't understand very well in C++ except that it's a constant expression. Can anyone explain how constexpr works here?

A constexpr function means that it must be computable at compile time if all of its arguments are also constexpr.

It's also basically explained at
https://github.com/PlummersSoftwareLLC/Primes/tree/drag-race/PrimeCPP/solution_3 : "Deviation: It does use the base algorithm but due to compile time optimization, a lot of the actual calculation does not happen at runtime"

and

"Note: this solution is limited to numbers up to around 50,000,000 (stack size limit on Mac OS it seems)." (due to the compile-time evaluation)

Jonas

Reply by email

Ryan Joseph
to Ryan Joseph: So Pascal failed pretty bad it looks like. ;) Ryan Joseph
Show quoted text 10 lines
On Jul 9, 2021, at 4:56 PM, Ryan Joseph wrote: > Current standings at the time of this video > Iterations per sec: > Ada: 67 > Pascal: 143 > Fastest language: 7301 > Slowest language: 1 So Pascal failed pretty bad it looks like. ;)

I just ran that unit with -O2 and got nearly ~6000 passes on my 2020 MacBook. The C++ solution #1 got about the same.

I guess that video is totally false or I'm missing something....

Regards,
Ryan Joseph

Reply by email

Sven Barth
to Ryan Joseph

Ryan Joseph via fpc-pascal schrieb am
So., 11. Juli 2021, 01:19:

Show quoted text 11 lines
> On Jul 10, 2021, at 11:18 AM, Jonas Maebe via fpc-pascal < > wrote: > > A constexpr function means that it must be computable at compile time if > all of its arguments are also constexpr. So like the "pure" functions that Gareth was working on? Seems to have moved on from the idea but I thought it was pretty interesting.

He's still working on that though he said that he needs to get a better grip on the compiler internals first.

Regards,
Sven

Reply by email