Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

HOLY MACRO!


devel / comp.lang.prolog / Re: SWI absurdly slow

SubjectAuthor
* SWI absurdly slowJulio Di Egidio
+- Re: SWI absurdly slowMild Shock
`* Re: SWI absurdly slowpeter.l...@gmail.com
 `* Re: SWI absurdly slowJulio Di Egidio
  +- Re: SWI absurdly slowMild Shock
  `* Re: SWI absurdly slowJulio Di Egidio
   `* Re: SWI absurdly slowMild Shock
    `- Re: SWI absurdly slowMild Shock

1
SWI absurdly slow

<ug3d9i$147h7$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2166&group=comp.lang.prolog#2166

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: julio@diegidio.name (Julio Di Egidio)
Newsgroups: comp.lang.prolog
Subject: SWI absurdly slow
Date: Tue, 10 Oct 2023 13:41:36 +0200
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <ug3d9i$147h7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Oct 2023 11:41:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d1adfb816ac7ceb18bde3e27414f4832";
logging-data="1187367"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hY2/BO04rTPuuZcfgmdSS8nHTPZOV2HY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:DlcGZ+Xe81X4oFmLbAva0VlQWH8=
Content-Language: en-GB
 by: Julio Di Egidio - Tue, 10 Oct 2023 11:41 UTC

Hi all,

I was playing with a prime number generator and making it work on both
SWI and GProlog, and I got an "interesting" performance result, where
the code is just pure Prolog with cut plus lists and some arithmetic:

=== SWI-Prolog (Windows, threaded, 64 bits, version 9.0.4): ==========

```prolog

?- consult('C:/Users/Julio/Desktop/prime_gen.pl').
true.

?- test_prime_gen(100).

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Elapsed CPU time: 0 ms
true.

?- test_prime_gen(100000, []).

Elapsed CPU time: 1813 %% (was 3657 ms in SWI 8.2.0)
true.

```

=== GNU Prolog 1.5.0 (Windows, 64 bits)*: =============================

*```prolog

| ?- consult('C:/Users/Julio/Desktop/prime_gen.pl').
compiling C:/Users/Julio/Desktop/prime_gen.pl for byte code...
C:/Users/Julio/Desktop/prime_gen.pl compiled, 93 lines read - 5924 bytes
written, 11 ms

yes
| ?- test_prime_gen(100).

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Elapsed CPU time: 0 ms

(15 ms) yes
| ?- test_prime_gen(100000, []).

Elapsed CPU time: 375 ms

(375 ms) yes

```

Source code is on Gist:
<https://gist.github.com/jp-diegidio/5d5855b555ebdbe4a1fec134fea4ce78>

Julio

Re: SWI absurdly slow

<ug3heo$2oru$1@solani.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2167&group=comp.lang.prolog#2167

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.prolog
Subject: Re: SWI absurdly slow
Date: Tue, 10 Oct 2023 14:52:41 +0200
Message-ID: <ug3heo$2oru$1@solani.org>
References: <ug3d9i$147h7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 10 Oct 2023 12:52:41 -0000 (UTC)
Injection-Info: solani.org;
logging-data="91006"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17.1
Cancel-Lock: sha1:48s0qdsU3KfPgKwsion1eUBC/WA=
In-Reply-To: <ug3d9i$147h7$1@dont-email.me>
X-User-ID: eJwNycEBwEAEBMCWcJZTjqzov4RkvoMTGkwPhGOxIuvGy9Fu7rDumN0+1UKc5fh6tmJr+y3gTXngYqn6h/ADdCcV5w==
 by: Mild Shock - Tue, 10 Oct 2023 12:52 UTC

Your GitHub says:
- SWI-Prolog (threaded, 64 bits, version 9.0.4)

Try SWI-Prolog 9.1.16, its a little bit better.
Around 16% faster. Might still not beat GNU Prolog though.

Julio Di Egidio schrieb:
> Hi all,
>
> I was playing with a prime number generator and making it work on both
> SWI and GProlog, and I got an "interesting" performance result, where
> the code is just pure Prolog with cut plus lists and some arithmetic:
>
> === SWI-Prolog (Windows, threaded, 64 bits, version 9.0.4): ==========
>
> ```prolog
>
> ?- consult('C:/Users/Julio/Desktop/prime_gen.pl').
> true.
>
> ?- test_prime_gen(100).
>
> 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
>
> Elapsed CPU time: 0 ms
> true.
>
> ?- test_prime_gen(100000, []).
>
> Elapsed CPU time: 1813  %% (was 3657 ms in SWI 8.2.0)
> true.
>
> ```
>
> === GNU Prolog 1.5.0 (Windows, 64 bits)*: =============================
>
> *```prolog
>
> | ?- consult('C:/Users/Julio/Desktop/prime_gen.pl').
> compiling C:/Users/Julio/Desktop/prime_gen.pl for byte code...
> C:/Users/Julio/Desktop/prime_gen.pl compiled, 93 lines read - 5924 bytes
> written, 11 ms
>
> yes
> | ?- test_prime_gen(100).
>
> 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
>
> Elapsed CPU time: 0 ms
>
> (15 ms) yes
> | ?- test_prime_gen(100000, []).
>
> Elapsed CPU time: 375 ms
>
> (375 ms) yes
>
> ```
>
> Source code is on Gist:
> <https://gist.github.com/jp-diegidio/5d5855b555ebdbe4a1fec134fea4ce78>
>
> Julio

Re: SWI absurdly slow

<f86ca575-c809-4352-8e1f-ea377b47b09bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2168&group=comp.lang.prolog#2168

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a37:e309:0:b0:774:20c6:7c30 with SMTP id y9-20020a37e309000000b0077420c67c30mr228095qki.12.1696950833632;
Tue, 10 Oct 2023 08:13:53 -0700 (PDT)
X-Received: by 2002:a05:6830:1142:b0:6c2:10e1:9d6f with SMTP id
x2-20020a056830114200b006c210e19d6fmr5711302otq.6.1696950833352; Tue, 10 Oct
2023 08:13:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Tue, 10 Oct 2023 08:13:52 -0700 (PDT)
In-Reply-To: <ug3d9i$147h7$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3ec0:bdb0:dc6f:c503:2310:c2d4;
posting-account=9gAkzgoAAABofvlOzclSGAYgk2QpaXiQ
NNTP-Posting-Host: 2600:1700:3ec0:bdb0:dc6f:c503:2310:c2d4
References: <ug3d9i$147h7$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f86ca575-c809-4352-8e1f-ea377b47b09bn@googlegroups.com>
Subject: Re: SWI absurdly slow
From: peter.ludemann@gmail.com (peter.l...@gmail.com)
Injection-Date: Tue, 10 Oct 2023 15:13:53 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3467
 by: peter.l...@gmail.com - Tue, 10 Oct 2023 15:13 UTC

On Tuesday, October 10, 2023 at 4:41:46 AM UTC-7, Julio Di Egidio wrote:
> Hi all,
>
> I was playing with a prime number generator and making it work on both
> SWI and GProlog, and I got an "interesting" performance result, where
> the code is just pure Prolog with cut plus lists and some arithmetic:
>
> === SWI-Prolog (Windows, threaded, 64 bits, version 9.0.4): ==========
>
> ```prolog
>
> ?- consult('C:/Users/Julio/Desktop/prime_gen.pl').
> true.
>
> ?- test_prime_gen(100).
>
> 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
>
> Elapsed CPU time: 0 ms
> true.
>
> ?- test_prime_gen(100000, []).
>
> Elapsed CPU time: 1813 %% (was 3657 ms in SWI 8.2.0)
> true.
>
> ```
>
> === GNU Prolog 1.5.0 (Windows, 64 bits)*: =============================
>
> *```prolog
>
> | ?- consult('C:/Users/Julio/Desktop/prime_gen.pl').
> compiling C:/Users/Julio/Desktop/prime_gen.pl for byte code...
> C:/Users/Julio/Desktop/prime_gen.pl compiled, 93 lines read - 5924 bytes
> written, 11 ms
>
> yes
> | ?- test_prime_gen(100).
>
> 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
>
> Elapsed CPU time: 0 ms
>
> (15 ms) yes
> | ?- test_prime_gen(100000, []).
>
> Elapsed CPU time: 375 ms
>
> (375 ms) yes
>
> ```
>
> Source code is on Gist:
> <https://gist.github.com/jp-diegidio/5d5855b555ebdbe4a1fec134fea4ce78>
>
> Julio

I ran the profiler on your code with SWI-Prolog, and the top items were:
94.6% append/3
10.4% $garbage_collect/1
4.8% prime_gen_comp/2

append/3 is just a regular predicate in SWI-Prolog; I don't know how it's implemented in GNU-Prolog, but if it's written in C, that could account for a lot of the difference.

PS: I got about 5% improvement with SWI-Prolog by specifying the "-O" (optimise) flag ... that would made the calls to is/2 and >/2 faster.

PPS: it's easy to get rid of the call to append/3. For example, you can change prime_gen_do/4 to prime_gen_do//4.

Re: SWI absurdly slow

<ug3qrk$179ef$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2169&group=comp.lang.prolog#2169

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: julio@diegidio.name (Julio Di Egidio)
Newsgroups: comp.lang.prolog
Subject: Re: SWI absurdly slow
Date: Tue, 10 Oct 2023 17:33:06 +0200
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <ug3qrk$179ef$1@dont-email.me>
References: <ug3d9i$147h7$1@dont-email.me>
<f86ca575-c809-4352-8e1f-ea377b47b09bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 10 Oct 2023 15:33:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d1adfb816ac7ceb18bde3e27414f4832";
logging-data="1287631"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GUsBoKTw3++CoqjD/CkryNIm/L5jKNr0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:MDlAMFGQVHbbV/tzKbP/eRFtST8=
Content-Language: en-GB
In-Reply-To: <f86ca575-c809-4352-8e1f-ea377b47b09bn@googlegroups.com>
 by: Julio Di Egidio - Tue, 10 Oct 2023 15:33 UTC

On 10/10/2023 17:13, peter.l...@gmail.com wrote:
> On Tuesday, October 10, 2023 at 4:41:46 AM UTC-7, Julio Di Egidio wrote:<snip>
> I ran the profiler on your code with SWI-Prolog, and the top items were:
> 94.6% append/3
> 10.4% $garbage_collect/1
> 4.8% prime_gen_comp/2
>
> append/3 is just a regular predicate in SWI-Prolog; I don't know how it's
> implemented in GNU-Prolog, but if it's written in C, that could account for
> a lot of the difference.

Thanks, that makes sense. I shall get rid of that append with a
difference list, then the comparison should be fair (as to the
pure Prolog with cut plus basic arithmetic fragment).

Meanwhile, I guess I should rename the thread "append absurdly
slow in SWI". ;)

Julio

Re: SWI absurdly slow

<ug4680$32mp$1@solani.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2170&group=comp.lang.prolog#2170

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.prolog
Subject: Re: SWI absurdly slow
Date: Tue, 10 Oct 2023 20:47:28 +0200
Message-ID: <ug4680$32mp$1@solani.org>
References: <ug3d9i$147h7$1@dont-email.me>
<f86ca575-c809-4352-8e1f-ea377b47b09bn@googlegroups.com>
<ug3qrk$179ef$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 10 Oct 2023 18:47:28 -0000 (UTC)
Injection-Info: solani.org;
logging-data="101081"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17.1
Cancel-Lock: sha1:jhBS/gr4Hj7P317ddBMH+2m7A8o=
In-Reply-To: <ug3qrk$179ef$1@dont-email.me>
X-User-ID: eJwFwYEBwDAEBMCVBP9qHCL2H6F3MB7ecIKOxbImhpWSopqNcbdO7pm4NgemX73wqW5ch7S+783Ws6aoxA9SgRW2
 by: Mild Shock - Tue, 10 Oct 2023 18:47 UTC

GNU Prolog append/3 is a little faster, which is strange,
since GNU Prolog is more known to be faster for
arithmetic, since it doesn't have bigint,

but append/3 seems to be faster:

/* GNU Prolog (interpreted) */
?- between(1,1000000,_), fail; true.
(15 ms) yes

?- between(1,1000000,_), append([1,2,3,4,5],[6],_), fail; true
(109 ms) yes

/* SWI-Prolog */
?- time((between(1,1000000,_), fail; true)).
% 999,998 inferences, 0.031 CPU in 0.028 seconds (111% CPU, 31999936 Lips)
true.

?- time((between(1,1000000,_), append([1,2,3,4,5],[6],_), fail; true)).
% 6,999,998 inferences, 0.156 CPU in 0.155 seconds
(100% CPU, 44799987 Lips)
true.

Subtracting Loop Time I get:
GNU Prolog (interpreted): 94 ms
SWI-Prolog: 155-28 = 127 ms

GNU Prolog has a native implementation of append,
by Pl_Append_3 in a file list_c.c. Woa!

Julio Di Egidio schrieb:
> On 10/10/2023 17:13, peter.l...@gmail.com wrote:
>> On Tuesday, October 10, 2023 at 4:41:46 AM UTC-7, Julio Di Egidio
>> wrote:<snip>
>> I ran the profiler on your code with SWI-Prolog, and the top items were:
>>    94.6%  append/3
>>    10.4%  $garbage_collect/1
>>      4.8%  prime_gen_comp/2
>>
>> append/3 is just a regular predicate in SWI-Prolog; I don't know how it's
>> implemented in GNU-Prolog, but if it's written in C, that could
>> account for
>> a lot of the difference.
>
> Thanks, that makes sense.  I shall get rid of that append with a
> difference list, then the comparison should be fair (as to the
> pure Prolog with cut plus basic arithmetic fragment).
>
> Meanwhile, I guess I should rename the thread "append absurdly
> slow in SWI". ;)
>
> Julio
>

Re: SWI absurdly slow

<ug4vok$1jbo8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2173&group=comp.lang.prolog#2173

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: julio@diegidio.name (Julio Di Egidio)
Newsgroups: comp.lang.prolog
Subject: Re: SWI absurdly slow
Date: Wed, 11 Oct 2023 04:02:58 +0200
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <ug4vok$1jbo8$1@dont-email.me>
References: <ug3d9i$147h7$1@dont-email.me>
<f86ca575-c809-4352-8e1f-ea377b47b09bn@googlegroups.com>
<ug3qrk$179ef$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 11 Oct 2023 02:03:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fd82cefc954de4e8c46d5f8b72bd012c";
logging-data="1683208"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+48tbFlGn4ibSZD9S8CScZ6egPVOMuabg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kgHAeV2nQXvyIqvcS4a4CEDhuGI=
Content-Language: en-GB
In-Reply-To: <ug3qrk$179ef$1@dont-email.me>
 by: Julio Di Egidio - Wed, 11 Oct 2023 02:02 UTC

On 10/10/2023 17:33, Julio Di Egidio wrote:
> On 10/10/2023 17:13, peter.l...@gmail.com wrote:
>> On Tuesday, October 10, 2023 at 4:41:46 AM UTC-7, Julio Di Egidio
>> wrote:
> <snip>
>> I ran the profiler on your code with SWI-Prolog, and the top items were:
>>    94.6%  append/3
>>    10.4%  $garbage_collect/1
>>      4.8%  prime_gen_comp/2
>>
>> append/3 is just a regular predicate in SWI-Prolog; I don't know how it's
>> implemented in GNU-Prolog, but if it's written in C, that could
>> account for a lot of the difference.
>
> Thanks, that makes sense.  I shall get rid of that append with a
> difference list, then the comparison should be fair (as to the
> pure Prolog with cut plus basic arithmetic fragment).

I have published the updated version (with the diff list):
<https://gist.github.com/jp-diegidio/5d5855b555ebdbe4a1fec134fea4ce78>

Now indeed GNU Prolog seems just some 20% faster
(the difference might very well have to do with the
arithmetic, since SWI has arbitrary integers as well as
the rationals, plus of course floating point and maybe
something else by now, I have not been following: all
under one and the same predicate...):

?- forall(member(Max, [100000,200000]), test_prime_gen(Max, [rounds(30)])).

SWI:
Elapsed CPU time: 383 ms (avg. over 30 rounds)
Elapsed CPU time: 902 ms (avg. over 30 rounds)

GProlog:
Elapsed CPU time: 306 ms (avg. over 30 rounds)
Elapsed CPU time: 734 ms (avg. over 30 rounds)

And I'll leave it at that, as I cannot do anything really
precise. In fact, I cannot even be sure the 'statistics'
I am using are exactly the same on the two systems.

Julio

Re: SWI absurdly slow

<22d73eb1-31c3-43b7-9e0e-219736983f3dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2174&group=comp.lang.prolog#2174

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:ad4:4e66:0:b0:66d:b89:4f0d with SMTP id ec6-20020ad44e66000000b0066d0b894f0dmr7947qvb.1.1697015697240;
Wed, 11 Oct 2023 02:14:57 -0700 (PDT)
X-Received: by 2002:a05:6870:1a92:b0:1dd:908e:4a7a with SMTP id
ef18-20020a0568701a9200b001dd908e4a7amr8289735oab.10.1697015696949; Wed, 11
Oct 2023 02:14:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!newsfeed.hasname.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Wed, 11 Oct 2023 02:14:56 -0700 (PDT)
In-Reply-To: <ug4vok$1jbo8$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.50.239; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.50.239
References: <ug3d9i$147h7$1@dont-email.me> <f86ca575-c809-4352-8e1f-ea377b47b09bn@googlegroups.com>
<ug3qrk$179ef$1@dont-email.me> <ug4vok$1jbo8$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <22d73eb1-31c3-43b7-9e0e-219736983f3dn@googlegroups.com>
Subject: Re: SWI absurdly slow
From: bursejan@gmail.com (Mild Shock)
Injection-Date: Wed, 11 Oct 2023 09:14:57 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3955
 by: Mild Shock - Wed, 11 Oct 2023 09:14 UTC

Because GNU Prolog has a hand written append/3,
this here doesn't run indefinitely:

test(X) :- append(Y, X, [1,2,3|Y]).

Whereas in SWI-Prolog it runs indefinitely. So the hand
written C code lacks some garbage collection.

Here are the run results:

/* GNU Prolog 1.5.0 */
?- test(X).
X = [1,2,3] ? ;
X = [2,3,1] ? ;
X = [3,1,2] ?

?- test(X), fail; true.
%%% Dialog Window with global stack overflow
%%% After dismissing the Dialog Window GNU Prolog exists

/* SWI-Prolog 9.1.6 */
?- test(X).
X = [1, 2, 3] ;
X = [2, 3, 1] ;
X = [3, 1, 2] .

?- test(X), fail; true.
%%% runs indefinitely, you can watch the thread monitor, see how memory is reclaimed
%%% Responds to Ctrl-C and can be aborted, will gracefully return to top-level

Julio Di Egidio schrieb am Mittwoch, 11. Oktober 2023 um 04:03:26 UTC+2:
> On 10/10/2023 17:33, Julio Di Egidio wrote:
> > On 10/10/2023 17:13, peter.l...@gmail.com wrote:
> >> On Tuesday, October 10, 2023 at 4:41:46 AM UTC-7, Julio Di Egidio
> >> wrote:
> > <snip>
> >> I ran the profiler on your code with SWI-Prolog, and the top items were:
> >> 94.6% append/3
> >> 10.4% $garbage_collect/1
> >> 4.8% prime_gen_comp/2
> >>
> >> append/3 is just a regular predicate in SWI-Prolog; I don't know how it's
> >> implemented in GNU-Prolog, but if it's written in C, that could
> >> account for a lot of the difference.
> >
> > Thanks, that makes sense. I shall get rid of that append with a
> > difference list, then the comparison should be fair (as to the
> > pure Prolog with cut plus basic arithmetic fragment).
> I have published the updated version (with the diff list):
> <https://gist.github.com/jp-diegidio/5d5855b555ebdbe4a1fec134fea4ce78>
>
> Now indeed GNU Prolog seems just some 20% faster
> (the difference might very well have to do with the
> arithmetic, since SWI has arbitrary integers as well as
> the rationals, plus of course floating point and maybe
> something else by now, I have not been following: all
> under one and the same predicate...):
>
> ?- forall(member(Max, [100000,200000]), test_prime_gen(Max, [rounds(30)])).
>
> SWI:
> Elapsed CPU time: 383 ms (avg. over 30 rounds)
> Elapsed CPU time: 902 ms (avg. over 30 rounds)
>
> GProlog:
> Elapsed CPU time: 306 ms (avg. over 30 rounds)
> Elapsed CPU time: 734 ms (avg. over 30 rounds)
>
> And I'll leave it at that, as I cannot do anything really
> precise. In fact, I cannot even be sure the 'statistics'
> I am using are exactly the same on the two systems.
>
> Julio

Re: SWI absurdly slow

<3266e050-9248-46f4-90c4-e62070bfe1ccn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2175&group=comp.lang.prolog#2175

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:ac8:7c53:0:b0:418:fab:2d2d with SMTP id o19-20020ac87c53000000b004180fab2d2dmr298319qtv.11.1697015924119;
Wed, 11 Oct 2023 02:18:44 -0700 (PDT)
X-Received: by 2002:a05:6870:6c1b:b0:1e9:7c4f:e262 with SMTP id
na27-20020a0568706c1b00b001e97c4fe262mr1224737oab.8.1697015923861; Wed, 11
Oct 2023 02:18:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Wed, 11 Oct 2023 02:18:43 -0700 (PDT)
In-Reply-To: <22d73eb1-31c3-43b7-9e0e-219736983f3dn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.50.239; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.50.239
References: <ug3d9i$147h7$1@dont-email.me> <f86ca575-c809-4352-8e1f-ea377b47b09bn@googlegroups.com>
<ug3qrk$179ef$1@dont-email.me> <ug4vok$1jbo8$1@dont-email.me> <22d73eb1-31c3-43b7-9e0e-219736983f3dn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3266e050-9248-46f4-90c4-e62070bfe1ccn@googlegroups.com>
Subject: Re: SWI absurdly slow
From: bursejan@gmail.com (Mild Shock)
Injection-Date: Wed, 11 Oct 2023 09:18:44 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 85
 by: Mild Shock - Wed, 11 Oct 2023 09:18 UTC

Credits go to:

Marquee in Prolog
https://stackoverflow.com/questions/77061142/marquee-in-prolog

Mild Shock schrieb am Mittwoch, 11. Oktober 2023 um 11:14:58 UTC+2:
> Because GNU Prolog has a hand written append/3,
> this here doesn't run indefinitely:
>
> test(X) :- append(Y, X, [1,2,3|Y]).
>
> Whereas in SWI-Prolog it runs indefinitely. So the hand
> written C code lacks some garbage collection.
>
> Here are the run results:
>
> /* GNU Prolog 1.5.0 */
> ?- test(X).
> X = [1,2,3] ? ;
> X = [2,3,1] ? ;
> X = [3,1,2] ?
>
> ?- test(X), fail; true.
> %%% Dialog Window with global stack overflow
> %%% After dismissing the Dialog Window GNU Prolog exists
>
> /* SWI-Prolog 9.1.6 */
> ?- test(X).
> X = [1, 2, 3] ;
> X = [2, 3, 1] ;
> X = [3, 1, 2] .
>
> ?- test(X), fail; true.
> %%% runs indefinitely, you can watch the thread monitor, see how memory is reclaimed
> %%% Responds to Ctrl-C and can be aborted, will gracefully return to top-level
> Julio Di Egidio schrieb am Mittwoch, 11. Oktober 2023 um 04:03:26 UTC+2:
> > On 10/10/2023 17:33, Julio Di Egidio wrote:
> > > On 10/10/2023 17:13, peter.l...@gmail.com wrote:
> > >> On Tuesday, October 10, 2023 at 4:41:46 AM UTC-7, Julio Di Egidio
> > >> wrote:
> > > <snip>
> > >> I ran the profiler on your code with SWI-Prolog, and the top items were:
> > >> 94.6% append/3
> > >> 10.4% $garbage_collect/1
> > >> 4.8% prime_gen_comp/2
> > >>
> > >> append/3 is just a regular predicate in SWI-Prolog; I don't know how it's
> > >> implemented in GNU-Prolog, but if it's written in C, that could
> > >> account for a lot of the difference.
> > >
> > > Thanks, that makes sense. I shall get rid of that append with a
> > > difference list, then the comparison should be fair (as to the
> > > pure Prolog with cut plus basic arithmetic fragment).
> > I have published the updated version (with the diff list):
> > <https://gist.github.com/jp-diegidio/5d5855b555ebdbe4a1fec134fea4ce78>
> >
> > Now indeed GNU Prolog seems just some 20% faster
> > (the difference might very well have to do with the
> > arithmetic, since SWI has arbitrary integers as well as
> > the rationals, plus of course floating point and maybe
> > something else by now, I have not been following: all
> > under one and the same predicate...):
> >
> > ?- forall(member(Max, [100000,200000]), test_prime_gen(Max, [rounds(30)])).
> >
> > SWI:
> > Elapsed CPU time: 383 ms (avg. over 30 rounds)
> > Elapsed CPU time: 902 ms (avg. over 30 rounds)
> >
> > GProlog:
> > Elapsed CPU time: 306 ms (avg. over 30 rounds)
> > Elapsed CPU time: 734 ms (avg. over 30 rounds)
> >
> > And I'll leave it at that, as I cannot do anything really
> > precise. In fact, I cannot even be sure the 'statistics'
> > I am using are exactly the same on the two systems.
> >
> > Julio

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor