Recent

Author Topic: FPC call c library speed very slow  (Read 2115 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC call c library speed very slow
« Reply #15 on: March 05, 2024, 07:05:03 am »
well, nobody else has efficiency issues with the code you provided.
Add me to the list:
Code: [Select]
$ cat forloop.c
#include <stdint.h>
#include <time.h>
#include <stdio.h>

void for_loop_time()
{
    int i, tmp = 0;
    clock_t t1 = clock();

    for (i = 0; i < 1024; i++)
    {
        tmp += i;
    }

    printf("space %d clock_t value %d \n", (int)(clock() - t1), tmp); //print tmp to prohibit gcc optimize
}

$ cat testforloop.pas
program testforloop;

{$link ./forloop.o}
{$linklib c}

uses
   CTypes, sysutils;

procedure for_loop_time; cdecl; external;

begin
    for_loop_time;
end.

$ cat forlooptest.c
void for_loop_time();

int main() {
    for_loop_time();
    return 0;
}

$ gcc -o forlooptest forlooptest.c forloop.o
$ ./forlooptest
space 1 clock_t value 523776

$ fpc testforloop.pas
Free Pascal Compiler version 3.3.1 [2024/01/01] for x86_64
Copyright (c) 1993-2023 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling testforloop.pas
Linking testforloop
testforloop.pas(13,5) Warning: "crtbegin.o" not found, this will probably cause a linking failure
testforloop.pas(13,5) Warning: "crtend.o" not found, this will probably cause a linking failure
13 lines compiled, 0.1 sec, 447056 bytes code, 187008 bytes data
2 warning(s) issued
$ ./testforloop
space 1 clock_t value 523776

 

TinyPortal © 2005-2018