On Friday, 2 April 2021 at 05:18:49 UTC, H. S. Teoh wrote:
On Fri, Apr 02, 2021 at 05:05:21AM +, mw via
Digitalmars-d-learn wrote: [...]
This is just an example, what if the exact length is not known
statically, is there a functions to trim the `\0`s?
What about `s.until('\0')`?
Example:
On Friday, 2 April 2021 at 04:32:53 UTC, mw wrote:
https://run.dlang.io/is/B4jcno
---
import std;
import std.conv : text;
void main()
{
char[6] s;
s = "abc";
writeln(s, s.length); // abc6, ok it's the static array's
length
string t = text("head-", s, "-tail");
writeln(t
On 02/04/2021 6:10 PM, Computermatronic wrote:
On Friday, 2 April 2021 at 05:02:52 UTC, mw wrote:
Ahh, I got what I see (from writeln) is not what get string here ;-)
And I just tried:
string t = text("head-", strip(s), "-tail");
It's the same behavior.
So how can I trim the leading & trai
On Fri, Apr 02, 2021 at 05:05:21AM +, mw via Digitalmars-d-learn wrote:
[...]
> This is just an example, what if the exact length is not known
> statically, is there a functions to trim the `\0`s?
Another way, if you want to avoid the extra allocation, slice the static
array with .indexOf:
On Fri, Apr 02, 2021 at 05:05:21AM +, mw via Digitalmars-d-learn wrote:
[...]
> This is just an example, what if the exact length is not known
> statically, is there a functions to trim the `\0`s?
What about `s.until('\0')`?
Example:
auto s = "abc\0\0\0def";
auto t = "blah" ~
On Friday, 2 April 2021 at 05:02:52 UTC, mw wrote:
Ahh, I got what I see (from writeln) is not what get string
here ;-)
And I just tried:
string t = text("head-", strip(s), "-tail");
It's the same behavior.
So how can I trim the leading & trailing `\0` from the static
char array?
strip on
On Friday, 2 April 2021 at 05:01:27 UTC, rikki cattermole wrote:
On 02/04/2021 5:51 PM, mw wrote:
Then how can I construct `t`? to make this assertion true:
assert(t == "head-abc-tail"); // failed!
Slice it.
string t = text("head-", s[0 .. 3], "-tail");
http://ddili.org/ders/d.en/slic
On 02/04/2021 5:51 PM, mw wrote:
Then how can I construct `t`? to make this assertion true:
assert(t == "head-abc-tail"); // failed!
Slice it.
string t = text("head-", s[0 .. 3], "-tail");
http://ddili.org/ders/d.en/slices.html
On Friday, 2 April 2021 at 04:54:07 UTC, Computermatronic wrote:
On Friday, 2 April 2021 at 04:49:22 UTC, mw wrote:
So you mean inside the writeln() call, the 0s are skipped?
Well, if I use `string t` as filename, it will try to looking
for a file called:
"head-abc\0\0\0-tail" instead of jus
On Fri, Apr 02, 2021 at 04:32:53AM +, mw via Digitalmars-d-learn wrote:
[...]
> ---
> import std;
> import std.conv : text;
>
>
> void main()
> {
> char[6] s;
> s = "abc";
> writeln(s, s.length); // abc6, ok it's the static array's length
>
> string t = text("head-", s, "-ta
On Friday, 2 April 2021 at 04:49:22 UTC, mw wrote:
On Friday, 2 April 2021 at 04:43:48 UTC, rikki cattermole wrote:
On 02/04/2021 5:38 PM, mw wrote:
On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole
wrote:
On 02/04/2021 5:32 PM, mw wrote:
---
import std;
import std.conv : text;
void
On Friday, 2 April 2021 at 04:49:22 UTC, mw wrote:
So you mean inside the writeln() call, the 0s are skipped?
Well, if I use `string t` as filename, it will try to looking
for a file called:
"head-abc\0\0\0-tail" instead of just "head-abc-tail" ?
or it's platform dependent?
I would imagine
On Friday, 2 April 2021 at 04:43:48 UTC, rikki cattermole wrote:
On 02/04/2021 5:38 PM, mw wrote:
On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole
wrote:
On 02/04/2021 5:32 PM, mw wrote:
---
import std;
import std.conv : text;
void main()
{
char[6] s;
s = "abc";
writeln(
On Friday, 2 April 2021 at 04:38:37 UTC, mw wrote:
On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote:
I don't get it, what do you mean by the assertion:
assert(t[9] == '\0');
t == "head-abc-tail"
Just tried this:
https://run.dlang.io/is/SFU5p4
```
import std;
import std.conv
On 02/04/2021 5:38 PM, mw wrote:
On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote:
On 02/04/2021 5:32 PM, mw wrote:
---
import std;
import std.conv : text;
void main()
{
char[6] s;
s = "abc";
writeln(s, s.length); // abc6, ok it's the static array's length
str
On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote:
On 02/04/2021 5:32 PM, mw wrote:
---
import std;
import std.conv : text;
void main()
{
char[6] s;
s = "abc";
writeln(s, s.length); // abc6, ok it's the static array's
length
string t = text("head-", s, "-tail"
On 02/04/2021 5:32 PM, mw wrote:
---
import std;
import std.conv : text;
void main()
{
char[6] s;
s = "abc";
writeln(s, s.length); // abc6, ok it's the static array's length
string t = text("head-", s, "-tail");
writeln(t, t.length); // head-abc-tail16, why?
assert(t[9]
https://run.dlang.io/is/B4jcno
---
import std;
import std.conv : text;
void main()
{
char[6] s;
s = "abc";
writeln(s, s.length); // abc6, ok it's the static array's
length
string t = text("head-", s, "-tail");
writeln(t, t.length); // head-abc-tail16, why?
}
---
Why th
On Fri, Apr 02, 2021 at 02:36:21AM +, Jon Degenhardt via
Digitalmars-d-learn wrote:
> On Thursday, 1 April 2021 at 19:55:05 UTC, H. S. Teoh wrote:
[...]
> > It's interesting that whenever a question about D's performance pops
> > up in the forums, people tend to reach for optimization flags.
On Thursday, 1 April 2021 at 19:55:05 UTC, H. S. Teoh wrote:
On Thu, Apr 01, 2021 at 07:25:53PM +, matheus via
Digitalmars-d-learn wrote: [...]
Since this is a "Learn" part of the Foruam, be careful with
"-boundscheck=off".
I mean for this little snippet is OK, but for a other projects
th
On Friday, 2 April 2021 at 00:03:32 UTC, Paul Backus wrote:
On Thursday, 1 April 2021 at 22:35:01 UTC, tsbockman wrote:
Is there a better way?
Here's a technique I've used:
...
As long as the compile-time check is correct, this is sound:
the @trusted lambda can be called from @safe code if an
On Thursday, 1 April 2021 at 22:35:01 UTC, tsbockman wrote:
Suppose I have a templated struct member function for which I
can compute at compile-time when the function is memory safe,
and when it is not. But, the compiler cannot correctly
determine this automatically.
What is the best way to
Suppose I have a templated struct member function for which I can
compute at compile-time when the function is memory safe, and
when it is not. But, the compiler cannot correctly determine this
automatically.
What is the best way to express this in code? Other than
straight-up duplicating the
On Thu, Apr 01, 2021 at 09:16:09PM +, Imperatorn via Digitalmars-d-learn
wrote:
> On Thursday, 1 April 2021 at 21:13:18 UTC, H. S. Teoh wrote:
[...]
> > Thanks for the very interesting information; so it looks like most
> > of the time spent is actually in copying array elements than
> > anyth
On Thursday, 1 April 2021 at 21:13:18 UTC, H. S. Teoh wrote:
On Thu, Apr 01, 2021 at 01:17:15PM -0700, Ali Çehreli via
Digitalmars-d-learn wrote:
[...]
[...]
[...]
Right, but in a typical program it's unpredictable whether
there will be unused pages after the array.
[...]
[...]
Thanks
On Thu, Apr 01, 2021 at 01:17:15PM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 4/1/21 12:55 PM, H. S. Teoh wrote:
>
> > - Constructing large arrays by appending 1 element at a time with
> > `~`. Obviously, this requires many array reallocations and the
> > associated copying
>
> And
On 4/1/21 12:55 PM, H. S. Teoh wrote:
> - Constructing large arrays by appending 1 element at a time with `~`.
>Obviously, this requires many array reallocations and the associated
>copying
And that may not be a contributing factor. :) The following program sees
just 15 allocations and
On 01.04.21 21:53, Steven Schveighoffer wrote:
Maybe, but I wasn't responding to that, just your statement not to
recommend -boundscheck=off. In any case, it wouldn't hurt, right?
Right.
On Thu, Apr 01, 2021 at 07:25:53PM +, matheus via Digitalmars-d-learn wrote:
[...]
> Since this is a "Learn" part of the Foruam, be careful with
> "-boundscheck=off".
>
> I mean for this little snippet is OK, but for a other projects this my
> be wrong, and as it says here:
> https://dlang.org
On 4/1/21 3:44 PM, ag0aep6g wrote:
On 01.04.21 21:36, Steven Schveighoffer wrote:
On 4/1/21 3:27 PM, ag0aep6g wrote:
On 01.04.21 21:00, Berni44 wrote:
```
ldc2 -O3 -release -boundscheck=off -flto=full
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d
```
[...]
Yes, but you can recommend
On 01.04.21 21:36, Steven Schveighoffer wrote:
On 4/1/21 3:27 PM, ag0aep6g wrote:
On 01.04.21 21:00, Berni44 wrote:
```
ldc2 -O3 -release -boundscheck=off -flto=full
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d
```
[...]
Yes, but you can recommend `-boundscheck=safeonly`, which leave
thanks, i tried 2 variants:
```d
struct Tnew {TBase payload; alias payload this;}
```
```d
enum Tnew : Tbase {init = Tbase.init}
```
both works, but 1-st not allow "2 level" cast:
```d
struct Xptr {void* payload; alias payload this;} //Xptr based on
void*
struct Xobj {Xptr payload; alias payload
On 4/1/21 3:27 PM, ag0aep6g wrote:
On 01.04.21 21:00, Berni44 wrote:
```
ldc2 -O3 -release -boundscheck=off -flto=full
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d
```
Please don't recommend `-boundscheck=off` to newbies. It's not just an
optimization. It breaks @safe. If you want t
On Thu, Apr 01, 2021 at 04:52:17PM +, Nestor via Digitalmars-d-learn wrote:
[...]
> ```
> import std.stdio;
> import std.random;
> import std.datetime.stopwatch : benchmark, StopWatch, AutoStart;
> import std.algorithm;
>
> void main()
> {
> auto sw = StopWatch(AutoStart.no);
> sw.star
On Thursday, 1 April 2021 at 19:00:08 UTC, Berni44 wrote:
Try using ldc2 instead of dmd:
```
ldc2 -O3 -release -boundscheck=off -flto=full
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d
```
should produce much better results.
Since this is a "Learn" part of the Foruam, be careful wit
On 01.04.21 21:00, Berni44 wrote:
```
ldc2 -O3 -release -boundscheck=off -flto=full
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d
```
Please don't recommend `-boundscheck=off` to newbies. It's not just an
optimization. It breaks @safe. If you want to do welding without eye
protection
On Thursday, 1 April 2021 at 19:00:08 UTC, Berni44 wrote:
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to
Go, but that is not the case neither using rdmd nor running
the executable generated by dmd. I am getting values betw
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to
Go, but that is not the case neither using rdmd nor running the
executable generated by dmd. I am getting values between
350-380 ms, and 81ms in Python.
Try using ldc2 inste
On Thursday, 1 April 2021 at 17:30:15 UTC, Chris Piker wrote:
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to
Go, but that is not the case neither using rdmd nor running
the executable generated by dmd. I am getting values
On Thursday, 1 April 2021 at 17:30:15 UTC, Chris Piker wrote:
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to
Go, but that is not the case neither using rdmd nor running
the executable generated by dmd. I am getting values
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to
Go, but that is not the case neither using rdmd nor running the
executable generated by dmd. I am getting values between
350-380 ms, and 81ms in Python.
Nice test. I'm new
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I am a python programmer and I am enjoying Dlang and learning
some programming insights on the way, thank everyone.
I have no formal education and also program JS and PHP.
Watching a video where a guy programs some simple code in
Python
On 4/1/21 10:15 AM, ag0aep6g wrote:
> Move `auto rnd = ...;` out of the loop, and you will get better times.
Doing that reduces the time about 15 fold.
Using Appender reduces it further a tiny bit:
import std.array;
// ...
Appender!(int[]) mylist;
// ...
mylist.data.sort();
Ali
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to
Go, but that is not the case neither using rdmd nor running the
executable generated by dmd. I am getting values between
350-380 ms, and 81ms in Python.
[...]
```
for (i
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I am a python programmer and I am enjoying Dlang and learning
some programming insights on the way, thank everyone.
[...]
Could you also post the python code for comparison?
On Thursday, 1 April 2021 at 17:16:06 UTC, Imperatorn wrote:
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I am a python programmer and I am enjoying Dlang and learning
some programming insights on the way, thank everyone.
[...]
Could you also post the python code for comparison?
I am a python programmer and I am enjoying Dlang and learning
some programming insights on the way, thank everyone.
I have no formal education and also program JS and PHP.
Watching a video where a guy programs some simple code in Python
and the same code in Go and compares speed I thought that
On 4/1/21 10:53 AM, ludo wrote:
The results are below (you can also git clone the repo + dub test):
| Concatenation method | benchmark in ms|
|-|-|
|with std: | 385 ms|
|with stdReserve: | 327 ms|
|with stdLength: | 29 ms|
|with Append
Hi fellow Dlangers,
I am working on an old codebase, and found a re-implementation of
standard dynamic arrays as a struct called [ArrayBuilder, visible
on my github](https://tinyurl.com/2nr25ytt)
The comment says:
```d
/**
* Behaves the same as built-in arrays, except about 6x faster
with c
Thank Steve,
I open a new thread with some corrections, better title, etc.
On Wednesday, 31 March 2021 at 22:05:12 UTC, Steven Schveighoffer
wrote:
On 3/31/21 5:32 PM, ludo wrote:
[...]
ArrayBuilder should be similar in performance to Appender. I
think part of the issue with appender could
On Thursday, 1 April 2021 at 12:07:17 UTC, WebFreak001 wrote:
You can add a custom init value if you want to allow one:
```d
enum Xobj : void* { init = null }
```
Thank you!
On Tuesday, 30 March 2021 at 19:02:09 UTC, novice2 wrote:
[...]
Strange syntax.
Behavour exactly what i want, but this code not works for me :(
enum Xobj : void*;
Xobj var; //DMD Error: enum test7.Xobj forward reference of
Xobj.init
You can add a custom init value if you want to allow o
On 4/1/21 2:30 AM, DLearner wrote:
> immutable uint MemSize=100; // Memory size in bytes.
> ubyte[MemSize] MemPool = 8; // Initialised to 8 for debugging.
Valid index values there are from 0 to 99, inclusive.
> WkPtr = &MemPool[0];
>
> counter = 1;
> while (counter <= 1
On Thursday, 1 April 2021 at 09:30:28 UTC, DLearner wrote:
On Wednesday, 31 March 2021 at 23:21:59 UTC, russhy wrote:
On Wednesday, 31 March 2021 at 17:54:38 UTC, DLearner wrote:
[...]
Can you show the print function?
Maybe the problem lies there?
Using rdmd, I believe the code below demon
On Wednesday, 31 March 2021 at 23:21:59 UTC, russhy wrote:
On Wednesday, 31 March 2021 at 17:54:38 UTC, DLearner wrote:
On Wednesday, 31 March 2021 at 17:46:25 UTC, Imperatorn wrote:
On Wednesday, 31 March 2021 at 17:27:44 UTC, DLearner wrote:
Hi
I did:
immutable uint MemSize=100; // Mem
55 matches
Mail list logo