Is a type not a symbol?
http://dlang.org/spec/template.html#TemplateTupleParameter says that an AliasSeq (wording needs to be updated) "is a sequence of any mix of types, expressions or symbols." Is a type not a symbol? I mean, alias can refer to both, no? -- Shriramana Sharma, Penguin #395953
: in template specialization vs constraint
import std.stdio; void func(T)(T v) { writeln(1); } void func(T: int)(T v) { writeln(2); } void func(T)(T v) if (is(T: int)) { writeln(3); } void main() { func(100); ubyte s = 200; func(s); } The above code prints 2 twice. A fwe questions: 1) At func(100) why isn't the compiler complaining that it is able to match two templates i.e. the ones printing 2 and 3? Is it that since the second one is specialized but the third one apparently isn't, the compiler just ignores the third one? 2) How come func(s) doesn't invoke the template that prints 3? `T: int` in the context of specialization means an exact match but in the context of constraints it means implicitly convertible, no? The specialization section under http://dlang.org/spec/template.html is not very clear about this IMHO. -- Shriramana Sharma, Penguin #395953
Re: Let dmd or ldc be easy to setup on Ubuntu
On Tuesday, 22 December 2015 at 14:37:21 UTC, Rikki Cattermole wrote: I'm confused. The commands listed e.g. $ sudo wget http://netcologne.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list $ sudo apt-get update && sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring && sudo apt-get update Should work. If it does not, please post output. Sorry, it works,but can't get any useful info.
Re: Let dmd or ldc be easy to setup on Ubuntu
On Tuesday, 22 December 2015 at 15:08:20 UTC, FrankLike wrote: On Tuesday, 22 December 2015 at 14:37:21 UTC, Rikki Cattermole wrote: I'm confused. The commands listed e.g. $ sudo wget http://netcologne.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list $ sudo apt-get update && sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring && sudo apt-get update Should work. If it does not, please post output. Sorry, it works,but can't get any useful info. sudo apt-get install dmd ← it's error. Now I setup by double click the 'dmd_2.069.2-0-amd64.deb' file,and setup it. then sudo apt-get install dub it's ok.
Re: : in template specialization vs constraint
On Tuesday, 22 December 2015 at 15:29:16 UTC, Shriramana Sharma wrote: 1) At func(100) why isn't the compiler complaining that it is able to match two templates i.e. the ones printing 2 and 3? Because the specialized one just wins the context. It only complains when there's two equal ones. Constraints serve only to add or remove the template from the consideration list. If the constraint fails, the compiler considers that template to not even exist. If it passes, it adds the template to the overload list and then proceeds like it normally would without looking at the constraint again. Since your constraint passed, #3 is added to the list along side #1 and #2. Then, since #2 is specialized, it gets picked instead of the others. 2) How come func(s) doesn't invoke the template that prints 3? `T: int` in the context of specialization means an exact match but in the context of constraints it means implicitly convertible, no? The specialization section under http://dlang.org/spec/template.html is not very clear about this IMHO. In specialization, it will implicitly convert, it will just select the best match available. Make #1: void func(T : ubyte)(T v) { writeln(1); } It will then use that for for the second line because it is a *better* match than :int, but :int still is a match so it works as a fallback.
Re: Is a type not a symbol?
On Tuesday, 22 December 2015 at 15:22:49 UTC, Shriramana Sharma wrote: Is a type not a symbol? I mean, alias can refer to both, no? Keywords aren't symbols so `int` is a type, but not a symbol and thus qualifies as `T` but not as `alias T`.
Re: Let dmd or ldc be easy to setup on Ubuntu
El 22/12/15 a les 18:28, Jordi Sayol via Digitalmars-d-learn ha escrit: > "d-lang" splits it in few deb packages: s/d-lang/d-apt/
Re: Most performant way of converting int to string
V Tue, 22 Dec 2015 18:39:16 + Ivan Kazmenko via Digitalmars-d-learnnapsáno: > On Tuesday, 22 December 2015 at 18:11:24 UTC, rumbu wrote: > > On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman > > wrote: > >> Sorry if this is a silly question but is the to! method from > >> the conv library the most efficient way of converting an > >> integer value to a string? > >> > >> e.g. > >> string s = to!string(100); > >> > >> I'm seeing a pretty dramatic slow down in my code when I use a > >> conversion like this (when looped over 10 million iterations > >> for benchmarking). > >> > >> Cheers! > > > > Converting numbers to string involves the most expensive known > > two operations : division and modulus by 10. > > When the base is known in advance, division and modulus can be > substituted by a few additions, subtractions and bit shifts. For > example, the Hacker's Delight book has a chapter dedicated to > that, as well as a freely available additional chapter > (www.hackersdelight.org/divcMore.pdf). > > Does DMD, or Phobos function to!(string), do anything like that? > The number of possible bases is not large anyway. I've heard > major C/C++ compilers do that, but have not looked for a proof > myself. Yes, IIRC, all D compilers should be able to change modulus and division to few additions, subtractions and bit shifts if base is known at compile time. And phobos use this: https://github.com/D-Programming-Language/phobos/pull/1452
MonoTime longevity
I discovered something potentially troublesome in druntime. Namely, applications that use MonoTime will break if run 18 hours after booting, according to a short program I wrote. Here's my code: ``` import core.time : MonoTime; auto mt = MonoTime.currTime; import std.stdio : writeln; writeln(mt.ticks / mt.ticksPerSecond / 60 / 60); // prints 18 (hours) shortly after boot ``` `mt.ticksPerSecond` is `1_000_000_000` on my system. I really hope I'm doing something wrong.
Re: MonoTime longevity
On Tuesday, 22 December 2015 at 20:07:58 UTC, Steven Schveighoffer wrote: MonoTime uses whatever precision is given to it by the OS. So if on your OS, ticksPerSecond is 1e9, then your OS clock wraps at 18 hours as well. Thanks, I didn't know that. I actually just realized that my use case doesn't need to rely on absolute clocks, so I'm safe.
Re: Most performant way of converting int to string
V Tue, 22 Dec 2015 18:11:24 + rumbu via Digitalmars-d-learnnapsáno: > On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman > wrote: > > Sorry if this is a silly question but is the to! method from > > the conv library the most efficient way of converting an > > integer value to a string? > > > > e.g. > > string s = to!string(100); > > > > I'm seeing a pretty dramatic slow down in my code when I use a > > conversion like this (when looped over 10 million iterations > > for benchmarking). > > > > Cheers! > > Converting numbers to string involves the most expensive known > two operations : division and modulus by 10. No, IIRC few months or maybe years I have optimize this so it does not use division and modulus
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my code when I use a conversion like this (when looped over 10 million iterations for benchmarking). Cheers! Converting numbers to string involves the most expensive known two operations : division and modulus by 10.
Re: Most performant way of converting int to string
V Tue, 22 Dec 2015 17:15:27 + Andrew Chapman via Digitalmars-d-learnnapsáno: > Sorry if this is a silly question but is the to! method from the > conv library the most efficient way of converting an integer > value to a string? > > e.g. > string s = to!string(100); > > I'm seeing a pretty dramatic slow down in my code when I use a > conversion like this (when looped over 10 million iterations for > benchmarking). > > Cheers! > > This is OK and expected :).
Re: Most performant way of converting int to string
V Tue, 22 Dec 2015 20:52:07 + rumbu via Digitalmars-d-learnnapsáno: > On Tuesday, 22 December 2015 at 19:45:46 UTC, Daniel Kozák wrote: > > V Tue, 22 Dec 2015 18:11:24 + > > rumbu via Digitalmars-d-learn > > > > napsáno: > > > >> On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman > >> wrote: > >> > Sorry if this is a silly question but is the to! method from > >> > the conv library the most efficient way of converting an > >> > integer value to a string? > >> > > >> > e.g. > >> > string s = to!string(100); > >> > > >> > I'm seeing a pretty dramatic slow down in my code when I use > >> > a conversion like this (when looped over 10 million > >> > iterations for benchmarking). > >> > > >> > Cheers! > >> > >> Converting numbers to string involves the most expensive known > >> two operations : division and modulus by 10. > > > > No, IIRC few months or maybe years I have optimize this so it > > does not use division and modulus > > It's using division and modulus, as expected: > > https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L5529 > > If the compiler is smart enough, maybe it will replace this by > well known multiplication trick. Yes compiler is smart enought so it will not use division and modulus as I say before :)
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 18:11:24 UTC, rumbu wrote: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my code when I use a conversion like this (when looped over 10 million iterations for benchmarking). Cheers! Converting numbers to string involves the most expensive known two operations : division and modulus by 10. Cool thanks, so essentially it's unavoidable - I have a background in PHP programming where we don't really get exposed to memory allocation, conversions etc. Good to learn. Cheers.
Re: MonoTime longevity
On 12/22/15 2:48 PM, Tanel Tagaväli wrote: I discovered something potentially troublesome in druntime. Namely, applications that use MonoTime will break if run 18 hours after booting, according to a short program I wrote. Here's my code: ``` import core.time : MonoTime; auto mt = MonoTime.currTime; import std.stdio : writeln; writeln(mt.ticks / mt.ticksPerSecond / 60 / 60); // prints 18 (hours) shortly after boot ``` `mt.ticksPerSecond` is `1_000_000_000` on my system. I really hope I'm doing something wrong. MonoTime uses whatever precision is given to it by the OS. So if on your OS, ticksPerSecond is 1e9, then your OS clock wraps at 18 hours as well. In a recent version of D, MonoTime was changed to support multiple clocks. Use MonoTimeImpl!SomeClockType to use a clock with a different number of ticks per second if one exists. You can also use std.datetime.Clock -Steve
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 20:52:07 UTC, rumbu wrote: On Tuesday, 22 December 2015 at 19:45:46 UTC, Daniel Kozák wrote: V Tue, 22 Dec 2015 18:11:24 + rumbu via Digitalmars-d-learnnapsáno: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: > Sorry if this is a silly question but is the to! method > from the conv library the most efficient way of converting > an integer value to a string? > > e.g. > string s = to!string(100); > > I'm seeing a pretty dramatic slow down in my code when I > use a conversion like this (when looped over 10 million > iterations for benchmarking). > > Cheers! Converting numbers to string involves the most expensive known two operations : division and modulus by 10. No, IIRC few months or maybe years I have optimize this so it does not use division and modulus It's using division and modulus, as expected: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L5529 If the compiler is smart enough, maybe it will replace this by well known multiplication trick. Tested it, I was right: No optimizations: two divisions, one for the modulus and one for the division itself Optimized: multiplication by 0xCCCD trick. http://imgur.com/a/lHeHe
Re: Most performant way of converting int to string
On Tue, Dec 22, 2015 at 08:54:35PM +0100, Daniel Kozák via Digitalmars-d-learn wrote: > V Tue, 22 Dec 2015 09:43:00 -0800 > "H. S. Teoh via Digitalmars-d-learn" >napsáno: > > > On Tue, Dec 22, 2015 at 05:23:11PM +, Andrew Chapman via > > Digitalmars-d-learn wrote: [...] > > > for({int i; i = 0;} i < num; i++) { > > > //string s = to!string(i); > > > Customer c = Customer(i, "Customer", "", i > > > * 2); string result = objS.serialize(c); > > > } > > > > > > If I uncomment the "string s" line I'm seeing a 20% increase in > > > running time, which given what's going on the rest of the code is > > > quite surprising. I've tried compiling with both dmd and ldc2 - > > > it's the same under both. > > [...] > > > > I wonder if the slowdown is caused by GC collection cycles (because > > calling to!string will allocate, and here you're making a very large > > number of small allocations, which is known to cause GC performance > > issues). > > > > Try inserting this before the loop: > > > > import core.memory; > > GC.disable(); > > > > Does this make a difference in the running time? > > > > > > T > > > This would not help. It would probably be worse. I was not suggesting this as a solution, it's merely a way to determine whether the performance issue is GC-related. T -- "Hi." "'Lo."
Re: Most performant way of converting int to string
V Tue, 22 Dec 2015 21:10:54 + rumbu via Digitalmars-d-learnnapsáno: > On Tuesday, 22 December 2015 at 20:52:07 UTC, rumbu wrote: > > On Tuesday, 22 December 2015 at 19:45:46 UTC, Daniel Kozák > > wrote: > >> V Tue, 22 Dec 2015 18:11:24 + > >> rumbu via Digitalmars-d-learn > >> > >> napsáno: > >> > >>> On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman > >>> wrote: > >>> > Sorry if this is a silly question but is the to! method > >>> > from the conv library the most efficient way of converting > >>> > an integer value to a string? > >>> > > >>> > e.g. > >>> > string s = to!string(100); > >>> > > >>> > I'm seeing a pretty dramatic slow down in my code when I > >>> > use a conversion like this (when looped over 10 million > >>> > iterations for benchmarking). > >>> > > >>> > Cheers! > >>> > >>> Converting numbers to string involves the most expensive > >>> known two operations : division and modulus by 10. > >> > >> No, IIRC few months or maybe years I have optimize this so it > >> does not use division and modulus > > > > It's using division and modulus, as expected: > > > > https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L5529 > > > > If the compiler is smart enough, maybe it will replace this by > > well known multiplication trick. > > Tested it, I was right: > > No optimizations: two divisions, one for the modulus and one for > the division itself > Optimized: multiplication by 0xCCCD trick. > > http://imgur.com/a/lHeHe > > Yes this is expected :).
Re: How is D doing?
On Tuesday, 22 December 2015 at 03:43:24 UTC, ShinraTensei wrote: A friend of mine told me that my post might have sounded a bit trollish i assure you that was not the case. In fact it sounds very nonsense to me. You know you just came here asking on a "D FORUM" if the "D Programming Language" will die anytime soon... So... expecting what? A fan confirming this?
Re: How is D doing?
On Tuesday, 22 December 2015 at 21:58:24 UTC, Cavanni wrote: On Tuesday, 22 December 2015 at 03:43:24 UTC, ShinraTensei wrote: A friend of mine told me that my post might have sounded a bit trollish i assure you that was not the case. In fact it sounds very nonsense to me. You know you just came here asking on a "D FORUM" if the "D Programming Language" will die anytime soon... So... expecting what? A fan confirming this? Actually yes. Even though people here are obviously fan's of D, a person is still capable of giving unbiased opinion of it. I am fan of many things i can certainly say aren't doing all that good and i still remain a fan.
Lots of D code
I have 843 programs written in D. 805 actually create an 32 bit exe in windows 10. I am running the latest D. Some just start to link and the linker disappears. Some just have issues I am not able figure out. I can attach the code and scripts I use to compile and run these. If anyone is willing to figure out why the 38 do not compile, I would appreciate code that works. The execute_bf_v2.d creates an exe that is small but takes about 1 hour to link on a 12 core processor with 64g of ram as 14tb of disk space. The rest link very fast. If anyone is interested, let me know. I would love to get the 38 working. Also there are a few that produce incorrect answers. The Generate_maze.d produces all but the last line of the maze. I added a line just for it. I do not understand why. All of the programs are from RosettaCode.org. The script to compile them generates a log file and you will see a few that the linker just stops No idea why. A few have 64K link errors no idea why. TIA, Steven
Re: MonoTime longevity
On Tuesday, December 22, 2015 15:07:58 Steven Schveighoffer via Digitalmars-d-learn wrote: > MonoTime uses whatever precision is given to it by the OS. So if on your > OS, ticksPerSecond is 1e9, then your OS clock wraps at 18 hours as well. 1e9 ticks per second should still take over 293 years to wrap around. writeln(seconds(long.max / cast(long)1e9)); prints out 15250 weeks, 1 day, 23 hours, 47 minutes, and 16 secs Even if the clock ticks were in picoseconds (1e12 ticks per second), the clock would still take over 15 weeks to wrap around from 0. The OP's writeln(mt.ticks / mt.ticksPerSecond / 60 / 60); // prints 18 (hours) simply indicates that the system clock thinks that 18 hours have passed since the start of the system clock. And there's no guarantee that the system clock starts at 0, so while it's a bit weird for it to be in the range of 18 hours shortly after boot, it's perfectly legal. The only risk would be if the clock started close enough to long.max to cause the clock to wrap around even though it would have had plenty of room at 0. So, unless I'm missing something here, there is no problem, and MonoTime will work fine for what the OP is looking to do. As I recall, in the initial PR for Monotime, we discussed its range based on various clock frequencies and concluded that long was plenty large for any clock frequency we were ever going to see; otherwise, we probably would have gone with something similar to what POSIX uses (timespec) and split out the seconds and ticks per second rather than simply use ticks per second. - Jonathan M Davis
Re: : in template specialization vs constraint
On 12/22/15 10:40 AM, Adam D. Ruppe wrote: In specialization, it will implicitly convert, it will just select the best match available. Make #1: void func(T : ubyte)(T v) { writeln(1); } It will then use that for for the second line because it is a *better* match than :int, but :int still is a match so it works as a fallback. Type specialization has some weird properties in this regard. Sometimes it needs to be exact or explicit, sometimes it doesn't. http://forum.dlang.org/post/rvflnpxwzetpcphwx...@forum.dlang.org -Steve
Re: Most performant way of converting int to string
On 12/22/15 12:15 PM, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my code when I use a conversion like this (when looped over 10 million iterations for benchmarking). Cheers! Does it need to be string? What about a mutable char buffer? If you are allocating and throwing away strings in a tight loop, simply reusing the buffer could save a ton of time. Look into std.format -Steve
Re: curl : access violation
On 12/22/2015 03:10 AM, Vic wrote: I am testing simple code in Geany (Windows 7, DMD compiler): import std.stdio,std.net.curl; void main() { // Return a char[] containing the content specified by an URL auto content = get("dlang.org"); } It compiled ok, but I get error after running exe file: object.Error@(0): Access Violation Your code works as is here: Linux, DMD64 D Compiler v2.069.0. Ali
Re: How is D doing?
On Tuesday, 22 December 2015 at 17:49:34 UTC, Jakob Jenkov wrote: On Tuesday, 22 December 2015 at 03:30:32 UTC, ShinraTensei wrote: I recently noticed massive increase in new languages for a person to jump into(Nim, Rust, Go...etc) but my question is weather the D is actually used anywhere or are there chances of it dying anytime soon. Check out Google Trends. Searches for D Tutorial still beats searches for Scala Tutorial by a big margin: https://google.com/trends/explore#q=d%20tutorial%2C%20scala%20tutorial Google Trends shows something interesting: https://google.com/trends/explore#q=%2Fm%2F01kbt7%2C%20%2Fm%2F0dsbpg6%2C%20%2Fm%2F091hdj%2C%20%2Fm%2F03j_q%2C%20C%2B%2B=q=Etc%2FGMT-2
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 18:27:12 UTC, cym13 wrote: ... I don't think there is anything in the standard library that would really help here as (if I read it correctly) it is mainly because of the conversion from ranges to arrays that this code is slow. Yes, it has been faster in past, when I last check and optimeze to!string. But because of @nogc it has been rewriten to Range base version which is slower. In this case it makes sense to add special version without @nogc (to!string will allocate memory anyway) which just use dup on buffer instead of make Range. I will probably make pull request tomorrow.
Re: Most performant way of converting int to string
On 12/22/2015 10:15 AM, Andrew Chapman wrote: > On Tuesday, 22 December 2015 at 18:11:24 UTC, rumbu wrote: >> Converting numbers to string involves the most expensive known two >> operations : division and modulus by 10. > > Cool thanks, so essentially it's unavoidable There is hope. :) > I have a background in PHP programming where we don't really get exposed to > memory allocation, conversions etc. You will love Andrei's recently-released presentations from code::dive in November 2015: Writing Fast Code I: https://www.youtube.com/watch?v=ph7FP0LnmcA Writing Fast Code II: https://www.youtube.com/watch?v=3_FXy3cT5C8 Three Cool Things about D: https://youtube.com/watch?v=FdpaBHyQNco The first one has an example of optimizing uint64ToAscii() at around 1:16:30: https://www.youtube.com/watch?feature=player_detailpage=ph7FP0LnmcA#t=4604 Ali
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 18:11:24 UTC, rumbu wrote: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my code when I use a conversion like this (when looped over 10 million iterations for benchmarking). Cheers! Converting numbers to string involves the most expensive known two operations : division and modulus by 10. When the base is known in advance, division and modulus can be substituted by a few additions, subtractions and bit shifts. For example, the Hacker's Delight book has a chapter dedicated to that, as well as a freely available additional chapter (www.hackersdelight.org/divcMore.pdf). Does DMD, or Phobos function to!(string), do anything like that? The number of possible bases is not large anyway. I've heard major C/C++ compilers do that, but have not looked for a proof myself.
Re: Most performant way of converting int to string
V Tue, 22 Dec 2015 09:43:00 -0800 "H. S. Teoh via Digitalmars-d-learn"napsáno: > On Tue, Dec 22, 2015 at 05:23:11PM +, Andrew Chapman via > Digitalmars-d-learn wrote: [...] > > for({int i; i = 0;} i < num; i++) { > > //string s = to!string(i); > > Customer c = Customer(i, "Customer", "", i > > * 2); string result = objS.serialize(c); > > } > > > > If I uncomment the "string s" line I'm seeing a 20% increase in > > running time, which given what's going on the rest of the code is > > quite surprising. I've tried compiling with both dmd and ldc2 - > > it's the same under both. > [...] > > I wonder if the slowdown is caused by GC collection cycles (because > calling to!string will allocate, and here you're making a very large > number of small allocations, which is known to cause GC performance > issues). > > Try inserting this before the loop: > > import core.memory; > GC.disable(); > > Does this make a difference in the running time? > > > T > This would not help. It would probably be worse.
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 17:43:00 UTC, H. S. Teoh wrote: I wonder if the slowdown is caused by GC collection cycles (because calling to!string will allocate, and here you're making a very large number of small allocations, which is known to cause GC performance issues). Try inserting this before the loop: import core.memory; GC.disable(); Does this make a difference in the running time? T Thanks! Unfortunately that actually makes it run slightly slower :-)
Re: Most performant way of converting int to string
V Tue, 22 Dec 2015 12:55:10 -0800 "H. S. Teoh via Digitalmars-d-learn"napsáno: > On Tue, Dec 22, 2015 at 08:54:35PM +0100, Daniel Kozák via > Digitalmars-d-learn wrote: > > V Tue, 22 Dec 2015 09:43:00 -0800 > > "H. S. Teoh via Digitalmars-d-learn" > > napsáno: > > > > > On Tue, Dec 22, 2015 at 05:23:11PM +, Andrew Chapman via > > > Digitalmars-d-learn wrote: [...] > > > > for({int i; i = 0;} i < num; i++) { > > > > //string s = to!string(i); > > > > Customer c = Customer(i, "Customer", > > > > "", i > > > > * 2); string result = objS.serialize(c); > > > > } > > > > > > > > If I uncomment the "string s" line I'm seeing a 20% increase in > > > > running time, which given what's going on the rest of the code > > > > is quite surprising. I've tried compiling with both dmd and > > > > ldc2 - it's the same under both. > > > [...] > > > > > > I wonder if the slowdown is caused by GC collection cycles > > > (because calling to!string will allocate, and here you're making > > > a very large number of small allocations, which is known to cause > > > GC performance issues). > > > > > > Try inserting this before the loop: > > > > > > import core.memory; > > > GC.disable(); > > > > > > Does this make a difference in the running time? > > > > > > > > > T > > > > > This would not help. It would probably be worse. > > I was not suggesting this as a solution, it's merely a way to > determine whether the performance issue is GC-related. > > > T > Ok :)
Re: segfault in invariant { assert(super); }
On Monday, 21 December 2015 at 20:29:14 UTC, Steven Schveighoffer wrote: 1) Is this recursion expected? Yes. assert calls the virtual invariant function, which in the case of super is equivalent to this. So you are essentially calling assert(this). 2) The example is a dustmite'd version of this: It seems like something you shouldn't do. AFAIK, invariant should not call any public functions on your existing class. Thanks for the reply! Yeah, this helps for a clearer picture of what's happening. In particular, even though all invariants of a class hierarchy are tested instead of only the most-subclassed-one, triggering the invariant check remains virtual. I didn't know that. Even if Base.f() is const, it's not allowed inside Derived.invariant(). This is again understandable: By OOP principles, Derived shouldn't impose further restrictions on Base than what Base imposes on itself already. (good idea to file an enhancement report). For that, I was trying earlier today to find the exact instances of when there is a warning, and when there is not. I didn't get warnings to come up consistently. (Even the case I described in question 2 doens't always give a warning.) I'd have to take a look at this some time again. -- Simon
Setting native OS thread name (eg, via prctl)
I have this trivial code where the main thread clones a child thread. import std.stdio; import core.thread; import std.concurrency; class DerivedThread : Thread { this() { super(); } void quit() { _quit = true; } private: void setOSThreadName() { // TODO: Is there a way to set the native OS thread name, worst case, via prctl? } void run() { setOSThreadName(); while(!_quit) { writeln("Hello from ", thisTid); Thread.sleep(dur!("seconds")(1)); } writeln("I'll exit now."); } bool _quit = false; string _threadName = "Derived"; } void main() { auto derived = new DerivedThread(); derived.start(); Thread.sleep(dur!("seconds")(4)); derived.quit(); derived.join(); } What do i have to do to set the thread name in setOSThreadName (for instance, on Linux, it will reflect in proc filesystem).
Re: Setting native OS thread name (eg, via prctl)
On Tuesday, 22 December 2015 at 16:08:01 UTC, Dejan Lekic wrote: Arun, isn't that what the 'name' property is there for? Hi Dejan, Thanks for a quick reply. Setting the name property is not reflecting in the OS level. May be it is just used only at the object level? After setting the thread name, I would like to see the it reflect, for instance, in the output of `top` command. You can press H in top to toggle threads and see their names there. Cheers.
curl : access violation
I am testing simple code in Geany (Windows 7, DMD compiler): import std.stdio,std.net.curl; void main() { // Return a char[] containing the content specified by an URL auto content = get("dlang.org"); } It compiled ok, but I get error after running exe file: object.Error@(0): Access Violation
Re: Socket - handling large numbers of incoming connections
Am Mon, 21 Dec 2015 23:29:14 + schrieb Adam D. Ruppe: > On Monday, 21 December 2015 at 23:17:45 UTC, Daniel Kozák wrote: > > If you want to reinvent the wheel you can use > > [...] it isn't like the bundled functions with the OS are > hard to use [...] > epoll and similar interfaces are not difficult to use. But you need to be careful to handle all error conditions caused by low level posix io calls (read/write) correctly. (Partial reads/writes, How do you handle EINTR? How do you handle error codes returned by the close function*? ...) * http://lwn.net/Articles/576478/
Re: Socket - handling large numbers of incoming connections
The same as in C [1]. Just change #include to import core.sys.posix.poll; [1] http://linux.die.net/man/2/poll I have a background in Java, so I am a bit handicapped :-)
Re: How is D doing?
On Tuesday, 22 December 2015 at 03:30:32 UTC, ShinraTensei wrote: I recently noticed massive increase in new languages for a person to jump into(Nim, Rust, Go...etc) but my question is weather the D is actually used anywhere or are there chances of it dying anytime soon. So far I've tried a while bunch of languages and i do like D the most, since i am used to C/C++ syntax also Java a bit, but i don't like Java. Now i'm trying to can C/C++ and get accustomed to something more modern so D is my choice unless its a dead language. I'm not looking into D for job opportunities. Just writing programs for my own amusement and maybe even profit some day. I know this question has been answered, but I wanted to provide some hard facts for future visitors. 1. Downloads of the DMD compiler have been fluctuating between 1000 and 1600 per day: http://erdani.com/d/downloads.daily.png That number only captures downloads of one compiler from one source. 2. Books on the language. Packt published D Cookbook in 2014. They have already published Learning D in 2015 and will be publishing D Web Development in January. Clearly, in that publisher's experience, D is becoming a sufficiently popular language to invest in it. Other books (not with that publisher) are currently in progress. 3. The D Language Foundation. Andrei quit his job a few months ago to work on D and the D Language Foundation full time. http://forum.dlang.org/post/xsqrdgwnzehdmfmvc...@forum.dlang.org 4. The large number of participants on the main development forum. Not all of them contribute, but it indicates a strong interest in the language to post there.
Re: Socket - handling large numbers of incoming connections
Thanks, everyone, I have looked a bit at different frameworks, and it seems that libasync might have a decently narrow scope to fit what I need. I have a background in Java, so a lot of this OS-specific stuff is new to me (EPoll etc.). In Java that stuff is used under the hood for you, without you knowing anything about it. Java just chooses the best option for the given OS. This is easy to use, but of course gives you less control.
Re: Set color to a single point in Cairo
On Sunday, 20 December 2015 at 01:17:50 UTC, Basile B. wrote: On Saturday, 19 December 2015 at 14:16:23 UTC, TheDGuy wrote: is it possible to set the color of a single pixel with Cairo? Not like you would do with a classic canvas (2d grid), because colors are applied with `cairo_fill()` and `cairo_stroke()` on a particular path. but you can define a path that represents a single pixel and fill it: ``` cairo_rectangle (cr, x, y, 1, 1); // 1 pix rectangle cairo_set_source_rgba (cr, 0, 0, 0, 1); // color cairo_fill (cr); // fill the rectangle with source rgba ``` However cairo is node made to be used like this. The workflow is usually more based on stacked layers (1 layer = 1 path) with different filling, different transparency. I did something similar here : https://github.com/Zardoz89/DEDCPU-16/blob/master/src/lem1802_fontview.d#L287 I need to clean these code...
Re: Setting native OS thread name (eg, via prctl)
Arun, isn't that what the 'name' property is there for?
Re: Let dmd or ldc be easy to setup on Ubuntu
On 23/12/15 3:32 AM, FrankLike wrote: On Tuesday, 22 December 2015 at 14:11:29 UTC, Rikki Cattermole wrote: On 23/12/15 3:09 AM, FrankLike wrote: Now,we can't setup dmd or ldc like this: sudo apt-get install dmd sudo apt-get install ldc2 If I set 'The Installation Source' is : deb http://downloads.dlang.org/releases/2015/ main But it's error,why? Thank you. dlang.org does not host a apt repository. There is one on sourceforge for just this however. http://d-apt.sourceforge.net/ deb http://d-apt.sourceforge.net/ trusty main 'The Installation Source' is ok,but in Terminal it's error. Do you have some detail about 'The Installation Source' for dmd or ldc? Thank you. I'm confused. The commands listed e.g. $ sudo wget http://netcologne.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list $ sudo apt-get update && sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring && sudo apt-get update Should work. If it does not, please post output.
Let dmd or ldc be easy to setup on Ubuntu
Now,we can't setup dmd or ldc like this: sudo apt-get install dmd sudo apt-get install ldc2 If I set 'The Installation Source' is : deb http://downloads.dlang.org/releases/2015/ main But it's error,why? Thank you.
Re: Let dmd or ldc be easy to setup on Ubuntu
On 23/12/15 3:09 AM, FrankLike wrote: Now,we can't setup dmd or ldc like this: sudo apt-get install dmd sudo apt-get install ldc2 If I set 'The Installation Source' is : deb http://downloads.dlang.org/releases/2015/ main But it's error,why? Thank you. dlang.org does not host a apt repository. There is one on sourceforge for just this however. http://d-apt.sourceforge.net/
Re: Let dmd or ldc be easy to setup on Ubuntu
On Tuesday, 22 December 2015 at 14:11:29 UTC, Rikki Cattermole wrote: On 23/12/15 3:09 AM, FrankLike wrote: Now,we can't setup dmd or ldc like this: sudo apt-get install dmd sudo apt-get install ldc2 If I set 'The Installation Source' is : deb http://downloads.dlang.org/releases/2015/ main But it's error,why? Thank you. dlang.org does not host a apt repository. There is one on sourceforge for just this however. http://d-apt.sourceforge.net/ deb http://d-apt.sourceforge.net/ trusty main 'The Installation Source' is ok,but in Terminal it's error. Do you have some detail about 'The Installation Source' for dmd or ldc? Thank you.
Most performant way of converting int to string
Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my code when I use a conversion like this (when looped over 10 million iterations for benchmarking). Cheers!
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my code when I use a conversion like this (when looped over 10 million iterations for benchmarking). Cheers! Out of curiosity a slow down compared to what? No conversion at all?
Re: Let dmd or ldc be easy to setup on Ubuntu
El 22/12/15 a les 16:38, FrankLike via Digitalmars-d-learn ha escrit: > sudo apt-get install dmd ← it's error. dmd_2.069.2-0-amd64.deb from http://downloads.dlang.org/ is an all-in-one deb package, containing all the tools and libraries for each release. "d-lang" splits it in few deb packages: dmd-bin (compiler and other executable files) dmd-doc (documentation, man pages and examples) libphobos2-69 (shared library) libphobos2-dev (static library, symlink to shared library, module sources and pkg-config files) So if you want to install dmd compiler, just type: $ sudo apt-get install dmd-bin Regards, Jordi
Re: Most performant way of converting int to string
On Tue, Dec 22, 2015 at 05:23:11PM +, Andrew Chapman via Digitalmars-d-learn wrote: [...] > for({int i; i = 0;} i < num; i++) { > //string s = to!string(i); > Customer c = Customer(i, "Customer", "", i * 2); > string result = objS.serialize(c); > } > > If I uncomment the "string s" line I'm seeing a 20% increase in > running time, which given what's going on the rest of the code is > quite surprising. I've tried compiling with both dmd and ldc2 - it's > the same under both. [...] I wonder if the slowdown is caused by GC collection cycles (because calling to!string will allocate, and here you're making a very large number of small allocations, which is known to cause GC performance issues). Try inserting this before the loop: import core.memory; GC.disable(); Does this make a difference in the running time? T -- "Uhh, I'm still not here." -- KD, while "away" on ICQ.
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 17:18:16 UTC, cym13 wrote: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my code when I use a conversion like this (when looped over 10 million iterations for benchmarking). Cheers! Out of curiosity a slow down compared to what? No conversion at all? Yeah, if I include a simple conversion in my loop: for({int i; i = 0;} i < num; i++) { //string s = to!string(i); Customer c = Customer(i, "Customer", "", i * 2); string result = objS.serialize(c); } If I uncomment the "string s" line I'm seeing a 20% increase in running time, which given what's going on the rest of the code is quite surprising. I've tried compiling with both dmd and ldc2 - it's the same under both. Cheers.
Re: How is D doing?
On Tuesday, 22 December 2015 at 03:30:32 UTC, ShinraTensei wrote: I recently noticed massive increase in new languages for a person to jump into(Nim, Rust, Go...etc) but my question is weather the D is actually used anywhere or are there chances of it dying anytime soon. Check out Google Trends. Searches for D Tutorial still beats searches for Scala Tutorial by a big margin: https://google.com/trends/explore#q=d%20tutorial%2C%20scala%20tutorial
Re: Lots of D code
On Wednesday, 23 December 2015 at 00:59:53 UTC, steven kladitis wrote: I have 843 programs written in D. [...] All of the programs are from RosettaCode.org. The script to compile them generates a log file and you will see a few that the linker just stops No idea why. A few have 64K link errors no idea why. TIA, Steven I suggest you to put the 38 on GH (or the whole thing). They probably reveal some DMD bugs.
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 17:52:52 UTC, Andrew Chapman wrote: On Tuesday, 22 December 2015 at 17:43:00 UTC, H. S. Teoh wrote: I wonder if the slowdown is caused by GC collection cycles (because calling to!string will allocate, and here you're making a very large number of small allocations, which is known to cause GC performance issues). Try inserting this before the loop: import core.memory; GC.disable(); Does this make a difference in the running time? T Thanks! Unfortunately that actually makes it run slightly slower :-) I dislike guessing so here are my thought on it and the method I used to get there: First I used the following code: void f() { import std.conv; string s; foreach (i ; 0..1_000_000) { s = i.to!string; } } void g() { import core.memory; import std.conv; GC.disable; string s; foreach (i ; 0..1_000_000) { s = i.to!string; } } extern (C) int snprintf(char*, size_t, const char*, ...); void h() { char[10] s; foreach (i ; 0..1_000_000) { snprintf(cast(char*)s, 10, cast(char*)"%d", i); } } void main(string[] args) { f; // g; // h; } Note that for h I didn't really use a string, I used a char[10]. We should keep in mind that you may want to convert it to a proper string later. I compiled it three times (one per function) with `dmd -profile -profile=gc` and then ran it to get profiling data. I then compiled it with `dmd` while timing each execution 6 times and discarding the first time (as the first one has to heat the cache). The reason for the recompilation is that as the C code can't be profiled and profiling puts some overhead I wanted to get that off my shoulders while timing. Here are the average times: f: 0.50 user 0.00 system 95% CPU 0.530 total g: 0.49 user 0.01 system 96% CPU 0.522 total h: 0.17 user 0.00 system 92% CPU 0.188 total The GC profiler didn't find any allocation be it in f, g or h. The profiler was only available for f and g with very similar results (as they are the same function really, here is the interesting part): Timer Is 3579545 Ticks/Sec, Times are in Microsecs Num TreeFuncPer CallsTimeTimeCall 100 390439368 265416744 265 pure nothrow @safe char[] std.array.array!(std.conv.toChars!(10, char, 1, int).toChars(int).Result).array(std.conv.toChars!(10, char, 1, int).toChars(int).Result) 1008322499483224994 83 pure nothrow ref @nogc @safe std.conv.toChars!(10, char, 1, int).toChars(int).Result std.conv.toChars!(10, char, 1, int).toChars(int).Result.__ctor(int) 2370 118276850773190160 3 _Dmain 100 52573232835191373 35 pure nothrow @trusted immutable(char)[] std.conv.toImpl!(immutable(char)[], int).toImpl(int, uint, std.ascii.LetterCase) 5904369565933204064 5 pure nothrow ref @nogc @safe char std.conv.emplaceRef!(char, char).emplaceRef(ref char, ref char) 1003274590932745909 32 pure nothrow char[] std.array.arrayAllocImpl!(false, char[], ulong).arrayAllocImpl(ulong) 100 10010158616876591 16 pure nothrow @nogc @safe std.conv.toChars!(10, char, 1, int).toChars(int).Result std.conv.toChars!(10, char, 1, int).toChars(int) 5901307001413070014 2 pure nothrow @property @nogc @safe char std.conv.toChars!(10, char, 1, int).toChars(int).Result.front() 1004489944412153535 12 pure nothrow @trusted char[] std.array.uninitializedArray!(char[], ulong).uninitializedArray(ulong) 5901049159510491595 1 pure nothrow ref @nogc @safe char std.conv.emplaceImpl!(char).emplaceImpl!(char).emplaceImpl(ref char, ref char) 690 9952971 9952971 1 pure nothrow @property @nogc @safe bool std.conv.toChars!(10, char, 1, int).toChars(int).Result.empty() 10053086148 8186704 8 pure nothrow @trusted char[] std.array.array!(std.conv.toChars!(10, char, 1, int).toChars(int).Result).array(std.conv.toChars!(10, char, 1, int).toChars(int).Result).__lambda2() 100 530599849 4867521 4 pure nothrow @safe immutable(char)[] std.conv.toImpl!(immutable(char)[], int).toImpl(int) 100 534801618 4201769 4 pure nothrow @safe immutable(char)[] std.conv.to!(immutable(char)[]).to!(int).to(int) 590 2520677 2520677 0 pure nothrow @nogc @safe void std.conv.toChars!(10, char, 1, int).toChars(int).Result.popFront() 100 2138919 2138919 2 pure nothrow @nogc @trusted char[] std.array.array!(std.conv.toChars!(10, char, 1, int).toChars(int).Result).array(std.conv.toChars!(10,
Re: Most performant way of converting int to string
On Tuesday, 22 December 2015 at 19:45:46 UTC, Daniel Kozák wrote: V Tue, 22 Dec 2015 18:11:24 + rumbu via Digitalmars-d-learnnapsáno: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: > Sorry if this is a silly question but is the to! method from > the conv library the most efficient way of converting an > integer value to a string? > > e.g. > string s = to!string(100); > > I'm seeing a pretty dramatic slow down in my code when I use > a conversion like this (when looped over 10 million > iterations for benchmarking). > > Cheers! Converting numbers to string involves the most expensive known two operations : division and modulus by 10. No, IIRC few months or maybe years I have optimize this so it does not use division and modulus It's using division and modulus, as expected: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L5529 If the compiler is smart enough, maybe it will replace this by well known multiplication trick.