Re: Coding Challenges - Dlang or Generic
On Tuesday, 17 January 2023 at 21:50:06 UTC, matheus wrote: Have you compared the timings between this way (With ranges) and a normal way (Without ranges)? Of course it is possible to speed it up. However, even as it is, it is enough to see the power of intervals. I would argue that you'll get fast results even with DMD Compiler! ```d import std.stdio; import std.datetime.date; void main() { import std.datetime.stopwatch : benchmark, StopWatch; auto sw = StopWatch(); #line 1 sw.start(); enum xTest = 1200; auto title = enumToStr!DayOfWeek(2); auto date = Date(2023, 12, 1); auto range = MyCalendar(date); for(size_t test; test < xTest; range.popFront, ++test) { range.writeln; // month and year title.writefln!"%-(%s %)"; // days of week range.front.writeln; // formatted days } sw.stop(); writeln(sw.peek.total!"usecs"); } struct MyCalendar { import std.array : appender, replicate; import std.format : format, formattedWrite; import std.string : capitalize; Date date; enum empty = false; string front() { auto res = appender!string; int day, dow = date.dayOfWeek; // skip days: res.formattedWrite("%s", " ".replicate(dow * 3)); for(day = 1; day <= date.daysInMonth; ++day) { res.formattedWrite("%2s ", day); if(++dow % 7 == 0) res.put("\n"); } if(dow % 7) res.put("\n"); return res.data; } void popFront() { date.roll!"months"(1); } string toString() const { const currentYear = date.year; // Current Year const currentMonth = date.month; // Name of the month const monthAndYear = format("%s/%s:", currentMonth, currentYear); return capitalize(monthAndYear); } } auto enumToStr(E)(size_t len = 0) { import std.conv : to; string[] result; for(E x = E.min; x <= E.max; x++) { result ~= len ? x.to!string[0..len] : x.to!string; } return result; } ``` SDB@79
Re: Problem with ImportC example?
On Wednesday, 18 January 2023 at 02:05:34 UTC, zjh wrote: < ... `nightly`: Unresolved external symbol `__va_start`, function `_fwprintf_`. link error.
Re: Problem with ImportC example?
On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: With the latest version of 'dmd101.2',`dmd a.c`, I get: C:\Windows Kits\10\Include\10.0.22000.0\ucrt\corecrt_wstdio.h|1208| Error: function `a.__vswprintf_l` redeclaration with different type C:\Windows Kits\10\Include\10.0.22000.0\ucrt\corecrt_wstdio.h|1405| Error: function `a.__swprintf_l` redeclaration with different type
Re: Coding Challenges - Dlang or Generic
On Tuesday, 17 January 2023 at 23:27:03 UTC, matheus wrote: I ran in two sites: https://onecompiler.com/d and then https://godbolt.org/, with the latter I set LDC with -O2. My version (Source in the end) ran about 2x faster than the version with ranges. Well, the use of ranges is not the only difference. Can you try to run the following diagnostics program on this D Online Compiler platform? https://gist.github.com/ssvb/5c926ed9bc755900fdaac3b71a0f7cfd https://onecompiler.com/d/3yv7t9ap9 Gives me: HelloWorld.d(43): Error: undefined identifier `volatileStore` HelloWorld.d(44): Error: undefined identifier `volatileLoad` The volatileStore/volatileLoad functions used to be in `core.bitop` in the old versions of D compilers, but then moved to `core.volatile`. This kind of reshuffling is annoying, because supporting multiple versions of D compilers becomes unnecessarily difficult. After importing `core.volatile` in https://onecompiler.com/d/3yv7u9v7c now it prints: Detected compiler: DMD Performance warning: '-O' option was not used! Performance warning: '-release' option was not used! Performance warning: DMD generates much slower code than GDC or LDC! And this is a systematic problem with various online D compilers. Some of them don't bother to enable optimizations. Which isn't bad by itself, but makes it unsuitable for running benchmarks.
Re: Coding Challenges - Dlang or Generic
On Tuesday, 17 January 2023 at 23:08:19 UTC, Siarhei Siamashka wrote: On Tuesday, 17 January 2023 at 21:50:06 UTC, matheus wrote: Question: Have you compared the timings between this way (With ranges) and a normal way (Without ranges)? If you are intensively using ranges, UFCS or the other convenient high level language features, then the compiler choice does matter a lot. And only LDC compiler is able to produce fast binaries from such source code. ... I ran in two sites: https://onecompiler.com/d and then https://godbolt.org/, with the latter I set LDC with -O2. My version (Source in the end) ran about 2x faster than the version with ranges. ... I'm using D Online Compiler from different platforms but unfortunately I can't loop too much because they don't accept, but anyway a normal version runs almost twice faster than this version (With ranges). Can you try to run the following diagnostics program on this D Online Compiler platform? https://gist.github.com/ssvb/5c926ed9bc755900fdaac3b71a0f7cfd https://onecompiler.com/d/3yv7t9ap9 Gives me: HelloWorld.d(43): Error: undefined identifier `volatileStore` HelloWorld.d(44): Error: undefined identifier `volatileLoad` If you like I could send or post here a version without ranges to try out. Please post it. This is interesting. Like I said above I ran my version against the one with ranges (From: https://github.com/quickfur/dcal/blob/master/dcal.d), and I modified to just print the calendar for some year. With godbolt.org LDC -O2 my version ran 2x faster, and here is the source: import std.stdio, std.string, std.conv, std.range, std.datetime; import std.datetime.stopwatch : benchmark, StopWatch; void draw_months(int year ,int month, int columns){ int i; if(month>12){return;} auto columspace = " ".replicate(columns); write("\n"); for(i=0;i12){break;} write(" " ~ " ".replicate(11*(i>0)) ~ columspace,capitalize(to!string(Date(year,month+i,1).month))); } write("\n"); auto m = new string[][](columns); for(int j=0;j12){return;} for(i=1;i<8;++i){ write(to!string(Date(1899,1,i).dayOfWeek)[0..2], " "); } int c = DW[to!string(Date(year,month+j,1).dayOfWeek)]; auto dm = Date(2023,month+j,1).daysInMonth; for(i=0;i
Re: Coding Challenges - Dlang or Generic
On Tue, Jan 17, 2023 at 11:08:19PM +, Siarhei Siamashka via Digitalmars-d-learn wrote: > On Tuesday, 17 January 2023 at 21:50:06 UTC, matheus wrote: > > Question: Have you compared the timings between this way (With > > ranges) and a normal way (Without ranges)? > > If you are intensively using ranges, UFCS or the other convenient high > level language features, then the compiler choice does matter a lot. > And only LDC compiler is able to produce fast binaries from such > source code. > > GDC compiler has severe performance problems with inlining, unless LTO > is enabled. And it also allocates closures on stack. This may or may > not be fixed in the future, but today I can't recommend GDC if you > really care about performance. Interesting, I didn't know GDC has issues with inlining. I thought it was more-or-less on par with LDC in terms of the quality of code generation. Do you have a concrete example of this problem? > DMD compiler uses an outdated code generation backend from Digital > Mars C++ and will never be able to produce fast binaries. It > prioritizes fast compilation speed over everything else. [...] For anything performance related, I wouldn't even consider DMD. For all the 10+ years I've been using D, it has consistently produced executables that run about 20-30% slower than those produced by LDC or GDC, sometimes even up to 40%. For script-like programs or interactive apps that don't care about performance, DMD is fine for convenience and fast compile turnaround times. But as soon as performance matters, DMD is not even on my radar. T -- Heuristics are bug-ridden by definition. If they didn't have bugs, they'd be algorithms.
Re: Coding Challenges - Dlang or Generic
On Tuesday, 17 January 2023 at 21:50:06 UTC, matheus wrote: Question: Have you compared the timings between this way (With ranges) and a normal way (Without ranges)? If you are intensively using ranges, UFCS or the other convenient high level language features, then the compiler choice does matter a lot. And only LDC compiler is able to produce fast binaries from such source code. GDC compiler has severe performance problems with inlining, unless LTO is enabled. And it also allocates closures on stack. This may or may not be fixed in the future, but today I can't recommend GDC if you really care about performance. DMD compiler uses an outdated code generation backend from Digital Mars C++ and will never be able to produce fast binaries. It prioritizes fast compilation speed over everything else. I'm using D Online Compiler from different platforms but unfortunately I can't loop too much because they don't accept, but anyway a normal version runs almost twice faster than this version (With ranges). Can you try to run the following diagnostics program on this D Online Compiler platform? https://gist.github.com/ssvb/5c926ed9bc755900fdaac3b71a0f7cfd If you like I could send or post here a version without ranges to try out. Please post it. This is interesting.
Re: Problem with ImportC example?
On 1/17/23 12:02, DLearner wrote: C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c failed launching cl.exe /P /Zc:preprocessor [...] I don't use Windows for development but that error message makes me think cl.exe is not found to be executed. dmd relies on system compiler programs for its ImportC feature. cl.exe seems to be the compiler. I think it is the compiler. Can you run that program from the command line? Internet makes me think Visual Studio does not install it by default. (?) You may have to select C++ (or C?) when installing. (?) > FWIW, now tried a few standard D programs, work fine. > Suggesting VS is not the problem? Standard D programs don't need a C compiler; dmd is the D compiler. It needs a C compiler (to preprocess C sources) for ImportC. Ali
Re: Coding Challenges - Dlang or Generic
On Friday, 13 January 2023 at 21:12:17 UTC, Salih Dincer wrote: On Friday, 13 January 2023 at 18:59:01 UTC, matheus wrote: Unfortunately it's not working for me Yeah, it was an old development version. I also implemented another version the same day: * [Nested Class](https://forum.dlang.org/thread/vkjhkftvyprsivozy...@forum.dlang.org) * [Only One Struct](https://forum.dlang.org/post/thxvuddjimgswalzo...@forum.dlang.org) SDB@79 Sory... No problem. =] Question: Have you compared the timings between this way (With ranges) and a normal way (Without ranges)? I'm using D Online Compiler from different platforms but unfortunately I can't loop too much because they don't accept, but anyway a normal version runs almost twice faster than this version (With ranges). If you like I could send or post here a version without ranges to try out. Matheus.
Re: Problem with ImportC example?
On Tuesday, 17 January 2023 at 19:17:31 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 17:36:41 UTC, ryuukk_ wrote: On Tuesday, 17 January 2023 at 17:12:49 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 15:55:40 UTC, bachmeier wrote: [...] Downloaded latest dmd for windows from website: ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.101.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ``` But trial still failed: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c failed launching cl.exe /P /Zc:preprocessor /PD /nologo ex01.c /FIC:\D\dmd2\windows\bin\..\..\src\druntime\import\importc.h /Fiex01.i Error: C preprocess command cl.exe failed for file ex01.c, exit status 1 ``` It works for me ``` C:\Users\ryuukk\tmp>dmd -run ex01.c hello world ``` Double check your visual studio installation, something is wrong with your install probably Tried twice - same result. But VS installation is itself (IMO) not particularly intuitive. Would it be possible either to cite known working VS installation options on DLang website, or produce Windows installation script that takes such options automatically? FWIW, now tried a few standard D programs, work fine. Suggesting VS is not the problem?
Re: Problem with ImportC example?
On Tuesday, 17 January 2023 at 17:36:41 UTC, ryuukk_ wrote: On Tuesday, 17 January 2023 at 17:12:49 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 15:55:40 UTC, bachmeier wrote: On Tuesday, 17 January 2023 at 13:21:37 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 11:21:08 UTC, Dennis wrote: On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declarator before `#` ex01.c(5): Error: no type for declarator before `return` ex01.c(6): Error: no type for declarator before `}` ``` What is your `dmd --version`? I suspect you have a version where you still have to manually pre-process the .c file, instead of a more recent version which invokes the pre-processor itself. ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.100.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ``` You may want to use the nightly build if you're working with ImportC: https://github.com/dlang/dmd/releases/tag/nightly They're doing a lot of work with it. Downloaded latest dmd for windows from website: ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.101.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ``` But trial still failed: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c failed launching cl.exe /P /Zc:preprocessor /PD /nologo ex01.c /FIC:\D\dmd2\windows\bin\..\..\src\druntime\import\importc.h /Fiex01.i Error: C preprocess command cl.exe failed for file ex01.c, exit status 1 ``` It works for me ``` C:\Users\ryuukk\tmp>dmd -run ex01.c hello world ``` Double check your visual studio installation, something is wrong with your install probably Tried twice - same result. But VS installation is itself (IMO) not particularly intuitive. Would it be possible either to cite known working VS installation options on DLang website, or produce Windows installation script that takes such options automatically?
Re: Problem with ImportC example?
On Tuesday, 17 January 2023 at 17:12:49 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 15:55:40 UTC, bachmeier wrote: On Tuesday, 17 January 2023 at 13:21:37 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 11:21:08 UTC, Dennis wrote: On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declarator before `#` ex01.c(5): Error: no type for declarator before `return` ex01.c(6): Error: no type for declarator before `}` ``` What is your `dmd --version`? I suspect you have a version where you still have to manually pre-process the .c file, instead of a more recent version which invokes the pre-processor itself. ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.100.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ``` You may want to use the nightly build if you're working with ImportC: https://github.com/dlang/dmd/releases/tag/nightly They're doing a lot of work with it. Downloaded latest dmd for windows from website: ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.101.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ``` But trial still failed: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c failed launching cl.exe /P /Zc:preprocessor /PD /nologo ex01.c /FIC:\D\dmd2\windows\bin\..\..\src\druntime\import\importc.h /Fiex01.i Error: C preprocess command cl.exe failed for file ex01.c, exit status 1 ``` It works for me ``` C:\Users\ryuukk\tmp>dmd -run ex01.c hello world ``` Double check your visual studio installation, something is wrong with your install probably
Re: Problem with ImportC example?
On Tuesday, 17 January 2023 at 15:55:40 UTC, bachmeier wrote: On Tuesday, 17 January 2023 at 13:21:37 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 11:21:08 UTC, Dennis wrote: On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declarator before `#` ex01.c(5): Error: no type for declarator before `return` ex01.c(6): Error: no type for declarator before `}` ``` What is your `dmd --version`? I suspect you have a version where you still have to manually pre-process the .c file, instead of a more recent version which invokes the pre-processor itself. ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.100.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ``` You may want to use the nightly build if you're working with ImportC: https://github.com/dlang/dmd/releases/tag/nightly They're doing a lot of work with it. Downloaded latest dmd for windows from website: ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.101.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ``` But trial still failed: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c failed launching cl.exe /P /Zc:preprocessor /PD /nologo ex01.c /FIC:\D\dmd2\windows\bin\..\..\src\druntime\import\importc.h /Fiex01.i Error: C preprocess command cl.exe failed for file ex01.c, exit status 1 ```
Re: Problem with ImportC example?
On Tuesday, 17 January 2023 at 13:21:37 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 11:21:08 UTC, Dennis wrote: On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declarator before `#` ex01.c(5): Error: no type for declarator before `return` ex01.c(6): Error: no type for declarator before `}` ``` What is your `dmd --version`? I suspect you have a version where you still have to manually pre-process the .c file, instead of a more recent version which invokes the pre-processor itself. ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.100.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ``` You may want to use the nightly build if you're working with ImportC: https://github.com/dlang/dmd/releases/tag/nightly They're doing a lot of work with it.
Re: Problem with ImportC example?
On Tuesday, 17 January 2023 at 11:21:08 UTC, Dennis wrote: On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declarator before `#` ex01.c(5): Error: no type for declarator before `return` ex01.c(6): Error: no type for declarator before `}` ``` What is your `dmd --version`? I suspect you have a version where you still have to manually pre-process the .c file, instead of a more recent version which invokes the pre-processor itself. ``` C:\Users\SoftDev>dmd --version DMD32 D Compiler v2.100.2-dirty Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright ```
Re: Problem with ImportC example?
On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declarator before `#` ex01.c(5): Error: no type for declarator before `return` ex01.c(6): Error: no type for declarator before `}` ``` What is your `dmd --version`? I suspect you have a version where you still have to manually pre-process the .c file, instead of a more recent version which invokes the pre-processor itself.
Problem with ImportC example?
This relates to the first example under 41.1 Quick Examples. Stored as ex01.c, run as shown. ``` #include int main() { printf("hello world\n"); return 0; } ``` Produced: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declarator before `#` ex01.c(5): Error: no type for declarator before `return` ex01.c(6): Error: no type for declarator before `}` ```