Sign in Join

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

Mailing lists / fpc-pascal / 2020-01

"Hello world" syscalls

8 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

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

Vojtěch Čihák

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.000037          37         1           readlink  25.83    0.000031           8         4           ioctl  18.33    0.000022          22         1           write  17.50    0.000021           5         4           rt_sigaction   4.17    0.000005           5         1           getrlimit   3.33    0.000004           4         1           execve ------ ----------- ----------- --------- --------- ---------------- 100.00    0.000120                    12           total  
It results in 30kB binary, 12 syscalls total, 6 unique. IMO appropriate. Has the fact that strings are managed types some relevance here?  
Thanks, Vojtěch.

(FPC 3.0.4)

Michael Van Canneyt
to Vojtěch Čihák
Vojtěch Čihák wrote 24 lines
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.000037          37         1           readlink  25.83    0.000031           8         4           ioctl  18.33    0.000022          22         1           write  17.50    0.000021           5         4           rt_sigaction   4.17    0.000005           5         1           getrlimit   3.33    0.000004           4         1           execve ------ ----------- ----------- --------- --------- ---------------- 100.00    0.000120                    12           total

If I do the same, I get this:

% time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 0.00 0.000000 0 1 write 0.00 0.000000 0 4 rt_sigaction 0.00 0.000000 0 4 ioctl 0.00 0.000000 0 1 execve 0.00 0.000000 0 1 readlink 0.00 0.000000 0 1 getrlimit ------ ----------- ----------- --------- --------- ---------------- 100.00 0.000000 12 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.

James Richters
to Michael Van Canneyt

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 

Earlier message 75 lines
-----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.000037          37         1           readlink >  25.83    0.000031           8         4           ioctl >  18.33    0.000022          22         1           write >  17.50    0.000021           5         4           rt_sigaction >   4.17    0.000005           5         1           getrlimit >   3.33    0.000004           4         1           execve > ------ ----------- ----------- --------- --------- ---------------- > 100.00    0.000120                    12           total If I do the same, I get this: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 0.00 0.000000 0 1 write 0.00 0.000000 0 4 rt_sigaction 0.00 0.000000 0 4 ioctl 0.00 0.000000 0 1 execve 0.00 0.000000 0 1 readlink 0.00 0.000000 0 1 getrlimit ------ ----------- ----------- --------- --------- ---------------- 100.00 0.000000 12 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.
Marco van de Voort
to James Richters

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)

Marco van de Voort
to Vojtěch Čihák:   I found this article: https://drewdevault.com/2020/01/04/Slow.html but FPC is…

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

Show quoted text 15 lines
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

Graeme Geldenhuys
to Vojtěch Čihák:   I found this article: https://drewdevault.com/2020/01/04/Slow.html but FPC is…
Vojtěch Čihák wrote
I found this article: https://drewdevault.com/2020/01/04/Slow.html but FPC is missing, so I wrote simple:

On a side note, and for comparison... According to that website, he/she tested Java and got the following:

Lang Exec time Total syscalls Unique syscalls Size (KiB) Java 0.07s real 226 26 15743KiB

So the resulting Java.class is 16 MByte in size!!! How?

I did the same on my system here with the latest OpenJDK 8 & 11.0.5. The resulting size of the class file was identical with Java 8 & 11 and was as follows:

$ javac -version
javac 1.8.0_232
$ javac Test.java

$ ls -l Test*
-rw-rw-r-- 1 graemeg graemeg 413 Jan 8 22:54 Test.class -rw-rw-r-- 1 graemeg graemeg 115 Jan 8 22:53 Test.java

My resulting class file is only 413 bytes. So how does that website owner get 16 MByte?

Regarding Execution time. It is interesting to note that Java 11 was on avg 18.6% faster that Java 8.

As for the syscalls, not sure if I'm doing this right:

$ strace -C java Test
...snip....
% time seconds usecs/call calls syscall

98.51 0.006797 3399 2 futex 0.67 0.000046 2 21 mprotect 0.35 0.000024 24 1 clone 0.25 0.000017 9 2 munmap 0.13 0.000009 5 2 getpid 0.10 0.000007 0 27 mmap 0.00 0.000000 0 11 read ...snip...
------------------------------------------------------------ 100.00 0.006900 198 total

That's 26 syscalls less than that website. It is interesting that 98% of the time is spent with just two calls to futex. Clearly a very slow syscall compared to the others.

Regards,
Graeme

Vincent Snijders
to Graeme Geldenhuys

Op do 9 jan. 2020 om 00:47 schreef Graeme Geldenhuys <

Show quoted text 29 lines
: On 07/01/2020 1:28 am, Vojtěch Čihák via fpc-pascal wrote: > I found this article: https://drewdevault.com/2020/01/04/Slow.html > but FPC is missing, so I wrote simple: On a side note, and for comparison... According to that website, he/she tested Java and got the following: Lang Exec time Total syscalls Unique syscalls Size (KiB) Java 0.07s real 226 26 15743KiB So the resulting Java.class is 16 MByte in size!!! How? I did the same on my system here with the latest OpenJDK 8 & 11.0.5. The resulting size of the class file was identical with Java 8 & 11 and was as follows: $ javac Test.java $ ls -l Test* -rw-rw-r-- 1 graemeg graemeg 413 Jan 8 22:54 Test.class -rw-rw-r-- 1 graemeg graemeg 115 Jan 8 22:53 Test.java My resulting class file is only 413 bytes. So how does that website owner get 16 MByte?

Did you create a static program? Otherwise you must include the dynamic libraries it uses.

Vincent