Article View: comp.lang.c
Article #1957Re: C and its peasant 'ancestors'
From: Ross Finlayson
Date: Sat, 28 Nov 2026 22:18
Date: Sat, 28 Nov 2026 22:18
261 lines
9230 bytes
9230 bytes
On 11/28/2026 07:28 AM, bartc wrote:
> On 28/11/2026 04:54, Bonita Montero wrote:
>> Am 27.11.2026 um 22:36 schrieb Lawrence D’Oliveiro:
>>
>>> ... the end result is a horrible and unmaintainable mess.
>> The abstractions of C++ make C++ more readable and maintaineable as C.
>>
>
> Yet every example of C++ you've ever posted is always an unreadable,
> ugly mess of syntax.
>
> Not all that is the fault of the language - you seem to delight in using
> every obscure feature possible and have nested functions everywhere.
>
> Below is a recent post of yours about sorting in C++. It took me a while
> to realise it was actually testing two kinds of sort!
>
> It is frankly diabolical. It seems designed to obfuscate as much as
> possible.
>
> Below yours, is a version in my language, just to show the contrast.
> This one only tests a qsort approach, but everything about it is
> straightforward.
>
> And below that, is a C port. Not quite as clean, but considerably less
> scary-looking than your C++.
>
> As for timings, then for 10000 sorts of 4096 random integers in the i32
> range, they were:
>
> C++/g++-O3 qsrt 3.5 seconds
> C++/g++-O3 stdsort 1.5 seconds
> My lang 2.5 seconds
> C/gcc-O2 2.5 seconds
> C/bcc 2.5 seconds
>
> But I don't know what's going on in your qsrt, and I don't know what
> stdsort does; these will be algorithmic differences.
>
> However, this is what happens when optimisation is turned off in all
> cases (in my tools, that just means locals stay in memory):
>
> C++/g++-O0 qsrt 7.0 seconds
> C++/g++-O0 stdsort 16.8 seconds
> My lang -no 3.7 seconds
> C/gcc-O0 4.0 seconds
> C/bcc -no 4.0 seconds
>
> Now C++'s stdsort is more than twice as slow as your qsrt! And 4 times
> as slow as that 'isort' in C.
>
> There is a more than 10:1 difference between optimised/unoptimised for
> this C++ standard sort. Here is one more timing:
>
> QQ 15.0 seconds
>
> This is my dynamic scripting language on the same task. The sort routine
> (same as isort) is implemented /in the language/, it is not called as an
> internal function written in native code.
>
> So unoptimised C++ is slower than a scripting language!
>
>
> -----------------------------------------
> #include <iostream>
> #include <algorithm>
> #include <cstdlib>
> #include <chrono>
> #include <vector>
> #include <random>
>
> using namespace std;
> using namespace chrono;
>
> int main()
> {
> constexpr size_t
> N = 0x1000,
> Rounds = 10'000;
> auto test = []( auto fn ) -> double
> {
> time_point start = steady_clock::now();
> for( size_t r = Rounds; r; --r )
> fn();
> duration dur = steady_clock::now() - start;
> return (double)duration_cast<nanoseconds>( dur ).count();
> };
> vector<int>
> origin( N ),
> srt( N );
> mt19937_64 mt;
> for( int &i : origin )
> i = (int)mt();
> int dummy = 0;
> auto cpy = [&] { copy( origin.begin(), origin.end(), srt.begin() );
> dummy += srt[0]; };
> double tRef = test( cpy );
> auto qsrt = [&]
> {
> cpy();
> qsort( srt.data(), srt.size(), sizeof( int ), +[]( const
> void *lhs, const void *rhs ) -> int
> {
> int &iLhs = *(int *)lhs, &iRhs = *(int *)rhs;
> if( iLhs == iRhs )
> return 0;
> return iLhs < iRhs ? -1 : 1;
> } );
> dummy += srt[0];
> };
> double tQsrt = test( qsrt ) - tRef;
> auto stdSrt = [&]
> {
> cpy();
> sort( srt.begin(), srt.end(), less() );
> dummy += srt[0];
> };
> double tStdSrt = test( stdSrt ) - tRef;
> cout << tQsrt / tStdSrt << endl;
> return dummy;
> }
> -----------------------------------------
>
> proc main =
> const nn = 4096
> [nn]int data, sdata # int is i64
>
> for i to nn do
> data[i] := mrandomrange(i32.min, i32.max)
> end
>
> to 10'000 do
> sdata := data
> isort(sdata, 1, sdata.len)
> end
>
> for i to nn when i not in 10..nn-10 do
> println i, sdata[i]
> end
> end
>
> proc isort([]int &data, int ll, rr)=
> int pivot, i := ll, j := rr
>
> pivot:=data[(ll+rr)/2]
>
> repeat
> while pivot > data[i] and i<rr do ++i end
> while pivot < data[j] and j>ll do --j end
>
> if i<=j then
> swap(data[i], data[j])
> ++i
> --j
> end
> until i>j
>
> if ll<j then isort(data, ll, j) end
> if i<rr then isort(data, i, rr) end
> end
>
> --------------------------------------
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> void isort(int* data, int ll, int rr) {
> int pivot, i = ll, j = rr, t;
>
> pivot = data[(ll+rr)/2];
>
> do {
> while (pivot > data[i] && i<rr) ++i;
> while (pivot < data[j] && j>ll) --j;
>
> if (i<=j) {
> t=data[i]; data[i]=data[j]; data[j]=t;
> ++i;
> --j;
> }
> } while (!(i>j));
>
> if (ll<j) isort(data, ll, j);
> if (i<rr) isort(data, i, rr);
> }
>
> int main(void) {
> enum {N=4096};
> int data[N], sdata[N], i;
>
> for (i=0; i<N; ++i) data[i] = (rand()<<15) | rand();
>
> for (i=0; i<10000; ++i) {
> memcpy(sdata, data, sizeof(data));
> isort(sdata, 0, N-1);
> }
>
> for (i=0; i<N; ++i) if (i<10 || i>(N-10)) printf("%4d %d\n", i,
> sdata[i]);
> }
>
>
>
>
Montero's style has changed over the years, for example
when since introducing lambdas, accounts like the more
labeled style vis-a-vis the tail-recursion style,
various accounts of inclusion of annotations and like
likely and so on, various accounts of consideration of
exceptions, it varies.
Agreeably, it's obscurantic.
#ifndef H__STANDARD
#define H__STANDARD
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
#define C_AUTO __auto_type
#define C_NODISCARD __attribute__((warn_unused_result))
typedef unsigned char byte_t;
typedef char char_t;
typedef enum {
LEN_BUF_LINE = 64,
LEN_BUF_PAGE = 4096,
LEN_BUF_HUGE = 2 * 1024 * 1024
} len_buf_enum_t;
typedef byte_t buf_line_t[LEN_BUF_LINE];
typedef byte_t buf_page_t[LEN_BUF_PAGE];
typedef byte_t buf_huge_t[LEN_BUF_HUGE];
typedef enum {
LEN_NAME_SHORT = 16,
LEN_NAME = 32,
LEN_NAME_LONG = 64,
LEN_NAME_MAX = NAME_MAX
} len_name_enum_t;
typedef char_t name_short_t[LEN_NAME_SHORT];
typedef char_t name_t[LEN_NAME];
typedef char_t name_long_t[LEN_NAME_LONG];
typedef char_t name_max_t[LEN_NAME_MAX];
typedef timespec timespec_t;
#endif /* H__STANDARD */
Technical Details
Message-ID:
<Zricna9AgaHbzpb2nZ2dnZfqnPidnZ2d@giganews.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-3.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<11dup6q$v4j9$1@dont-email.me> <11e0kde$1jpvu$1@dont-email.me> <11e0r13$1lqm6$1@dont-email.me> <11e0uc0$1mtpv$1@raubtier-asyl.eternal-september.org> <11e7fj4$37l9$1@dont-email.me> <11e8oro$ft4l$1@raubtier-asyl.eternal-september.org> <11e8stp$hajr$1@dont-email.me> <11e8ti0$hhqa$1@dont-email.me> <11e8v24$i2mc$2@raubtier-asyl.eternal-september.org> <11e9045$ihk3$1@dont-email.me> <11e90a8$ikh0$1@dont-email.me> <11e90mv$io87$2@raubtier-asyl.eternal-september.org> <11e91ns$j5dv$1@dont-email.me> <11e92ff$jclo$1@raubtier-asyl.eternal-september.org> <11e95j2$kimu$1@dont-email.me> <11e96aa$kpta$1@raubtier-asyl.eternal-september.org> <11ect54$20qpr$3@dont-email.me> <11edmpn$2938p$1@raubtier-asyl.eternal-september.org> <11eerur$2me3k$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-3.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 28 Nov 2026 22:18:46 +0000 Subject: Re: C and its peasant 'ancestors' Newsgroups: comp.lang.c References: <11dup6q$v4j9$1@dont-email.me> <11e0kde$1jpvu$1@dont-email.me> <11e0r13$1lqm6$1@dont-email.me> <11e0uc0$1mtpv$1@raubtier-asyl.eternal-september.org> <11e7fj4$37l9$1@dont-email.me> <11e8oro$ft4l$1@raubtier-asyl.eternal-september.org> <11e8stp$hajr$1@dont-email.me> <11e8ti0$hhqa$1@dont-email.me> <11e8v24$i2mc$2@raubtier-asyl.eternal-september.org> <11e9045$ihk3$1@dont-email.me> <11e90a8$ikh0$1@dont-email.me> <11e90mv$io87$2@raubtier-asyl.eternal-september.org> <11e91ns$j5dv$1@dont-email.me> <11e92ff$jclo$1@raubtier-asyl.eternal-september.org> <11e95j2$kimu$1@dont-email.me> <11e96aa$kpta$1@raubtier-asyl.eternal-september.org> <11ect54$20qpr$3@dont-email.me> <11edmpn$2938p$1@raubtier-asyl.eternal-september.org> <11eerur$2me3k$1@dont-email.me> From: Ross Finlayson <ross.a.finlayson@gmail.com> Date: Sat, 28 Nov 2026 14:18:31 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <11eerur$2me3k$1@dont-email.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <Zricna9AgaHbzpb2nZ2dnZfqnPidnZ2d@giganews.com> Lines: 261 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-GGBC0bYsE+OXltkPdG/ceeutaOjLG8lpfWIjFOZs78pTjkK3mK2H8972YpjcQ9g7Cz4VGYOb0gFd6ui!q/zitD0bS9NRkIb5GQs6cbFXkSrGeIyyRCwLbbtFx+DcMOZRMiXBlOak2p52KfC3uqzYBiAMcN/F X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40