Deutsch English Français Italiano |
<v30auq$3kcu9$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: C23 thoughts and opinions Date: Sun, 26 May 2024 22:52:25 +0100 Organization: A noiseless patient Spider Lines: 97 Message-ID: <v30auq$3kcu9$1@dont-email.me> References: <v2l828$18v7f$1@dont-email.me> <00297443-2fee-48d4-81a0-9ff6ae6481e4@gmail.com> <v2lji1$1bbcp$1@dont-email.me> <87msoh5uh6.fsf@nosuchdomain.example.com> <f08d2c9f-5c2e-495d-b0bd-3f71bd301432@gmail.com> <v2nbp4$1o9h6$1@dont-email.me> <v2ng4n$1p3o2$1@dont-email.me> <87y18047jk.fsf@nosuchdomain.example.com> <87msoe1xxo.fsf@nosuchdomain.example.com> <v2sh19$2rle2$2@dont-email.me> <87ikz11osy.fsf@nosuchdomain.example.com> <v2v59g$3cr0f$1@dont-email.me> <v2v7ni$3d70v$1@dont-email.me> <20240526161832.000012a6@yahoo.com> <v2vka0$3f4a2$1@dont-email.me> <20240526193549.000031a8@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 26 May 2024 23:52:26 +0200 (CEST) Injection-Info: dont-email.me; posting-host="8e9185d4e0820a2f5b79db78e2103a30"; logging-data="3814345"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19csqQULMECvgR9jQ6+EoHN" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:PhzqxP/v7x1vZMpx3QHIZWl/ptk= In-Reply-To: <20240526193549.000031a8@yahoo.com> Content-Language: en-GB Bytes: 4187 On 26/05/2024 17:35, Michael S wrote: > #include <stdio.h> > #include <stdlib.h> > #include <ctype.h> > > int main(int argz, char** argv) > { > if (argz > 1) { > FILE* fp = fopen(argv[1], "wb"); > if (fp) { > char buf[2048]; > _Bool look_for_comma = 0; > for (;;) { > if (fgets(buf, sizeof(buf), stdin) != buf) > break; > > char* p = buf; > for (;;) { > char c = *p; > if (isgraph(c)) { > if (look_for_comma) { > if (c == ',') { > look_for_comma = 0; > ++p; > } else { > goto done; > } > } else { > char* endp; > long val = strtol(p, &endp, 0); > if (endp==p) // not a number > goto done; > fputc((unsigned char)val, fp); > p = endp; > look_for_comma = 1; > } > } else { > if (c == 0) > break; // end of line > ++p; // skip space or control character > } > } > } > done: > fclose(fp); > } else { > perror(argv[1]); > return 1; > } > } > return 0; > } I tried this on my 600MB data like this: C:\c>c fred.exe <data C:\c>fred --version clang version 18.1.0rc Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\c Since those bytes represent the contents of the clang compiler, I was able to run it afterwards. All versions across compilers/optimise levels seemed to give a constant time of 17-18 seconds. This is good compared with my initial 144 seconds (most compilers failed; you reported a similar test took several minutes). However, what's involved with a compiler is much elaborate than such a program. There's syntax, type-checking, code-generation... Still, I reported earlier an experimental change to my non-C compiler, which translated this same input to a program with that embedded binary (not just the binary itself) in under 6 seconds. That's three times as fast as the above result: C:\mapps>tm \mx2\mm -ext test2 # tm is timing tool Compiling test2.m to test2.exe TM: 5.86 # (timings vary) C:\mapps>test2 data is 119571969 bytes C:\mapps>type test2.m []byte data = ( include "data" 0) proc main= fprintln "data is # bytes", data.len end