Re: [fpc-pascal] "Hello world" syscalls

2020-01-07 Thread James Richters
How can 0% + 0%+ 0%+ 0%+ 0%+ 0% = 100% ?  looks like it just prints 100% all
the time and doesn't really add any total.  All those zeros seem strange
unless your computer is so fast that every call takes so much less than a
microsecond that I can't be measured.

James 

-Original Message-
From: fpc-pascal  On Behalf Of
Michael Van Canneyt
Sent: Monday, January 6, 2020 11:44 PM
To: Vojtěch Čihák via fpc-pascal 
Subject: Re: [fpc-pascal] "Hello world" syscalls



On Tue, 7 Jan 2020, Vojtěch Čihák via fpc-pascal wrote:

> Hi,
>  
> I found this article: https://drewdevault.com/2020/01/04/Slow.html
> but FPC is missing, so I wrote simple:
>  
> program Project1;
> begin
>   writeln('Hello world!');
> end.
>  
> $ fpc -O3 -XX Project1.pas
>  
> $ strace -C ./Project1
>  
> % time     seconds  usecs/call     calls    errors syscall
> -- --- --- - - 
>  30.83    0.37          37         1           readlink
>  25.83    0.31           8         4           ioctl
>  18.33    0.22          22         1           write
>  17.50    0.21           5         4           rt_sigaction
>   4.17    0.05           5         1           getrlimit
>   3.33    0.04           4         1           execve
> -- --- --- - - 
> 100.00    0.000120                    12           total

If I do the same, I get this:

% time seconds  usecs/call callserrors syscall
-- --- --- - - 
   0.000.00   0 1   write
   0.000.00   0 4   rt_sigaction
   0.000.00   0 4   ioctl
   0.000.00   0 1   execve
   0.000.00   0 1   readlink
   0.000.00   0 1   getrlimit
-- --- --- - - 
100.000.0012   total

>  
> It results in 30kB binary, 12 syscalls total, 6 unique. IMO appropriate.

Size of the binary is irrelevant.

> Has the fact that strings are managed types some relevance here?

No. And in your example, there are no managed strings, since shortstring
will be used.

The rtl (system unit in particular) just takes some setting up.
* execve is normal, you'll always have it.
* Readlink is to determine paramstr(0). 
* rt_sigaction is to set up runtime errors (signal handling). 
* getrlimit is to set up stack/heap checking. 
* ioctl() is to determine whether stdio file descriptors are terminals or
not.

These are all one-time calls. No amount of optimization will reduce this.

The real call: write(), happens only once, as it should be.

So these numbers are perfectly normal. 
In the lifetime of any real application, they're negligable.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] "Hello world" syscalls

2020-01-07 Thread Marco van de Voort


Op 2020-01-07 om 02:28 schreef Vojtěch Čihák via fpc-pascal:


I found this article: https://drewdevault.com/2020/01/04/Slow.html

but FPC is missing, so Iwrote simple:

program Project1;

begin

  writeln('Hello world!');

end.

$ fpc -O3 -XX Project1.pas

Add -Xm and look at the generated map file to see what symbols are 
included in the binary.


Most is code that is used in RTL initialization


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] "Hello world" syscalls

2020-01-07 Thread Marco van de Voort


Op 2020-01-07 om 14:29 schreef James Richters:

How can 0% + 0%+ 0%+ 0%+ 0%+ 0% = 100% ?  looks like it just prints 100% all
the time and doesn't really add any total.  All those zeros seem strange
unless your computer is so fast that every call takes so much less than a
microsecond that I can't be measured.
(I think the 100% is hardcoded, and the other values are zero because 
some profiling option in the kernel is not enabled)

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal