Re: The One Billion Row Challenge

2024-01-11 Thread Sergey via Digitalmars-d-learn
On Thursday, 11 January 2024 at 08:57:43 UTC, Christian Köstlin 
wrote:

Did someone already try to do this in dlang?
I guess it will be very hard to beat the java solutions running 
with graalvm!


https://news.ycombinator.com/item?id=38851337

Kind regards,
Christian


I think C++ people already beated Java's performance 
https://github.com/buybackoff/1brc?tab=readme-ov-file#native


Re: Generating custom toString for structs

2024-01-11 Thread cc via Digitalmars-d-learn

On Sunday, 7 January 2024 at 09:49:36 UTC, Renato wrote:
Hi, I wanted to customize the toString implementation for my 
structs.


So I wrote a mixin for doing that:


Alternative format similar to what you already have:
```d
import std.format;

mixin template ToStringMixin() {
void toString(W)(ref W writer) {
alias T = typeof(this);
		writer.formattedWrite("%s(\n", T.stringof); // See also: 
std.traits.fullyQualifiedName

static foreach (idx, field; T.tupleof) {
			writer.formattedWrite("\t%s: %s\n", T.tupleof[idx].stringof, 
this.tupleof[idx]);

}
put(writer, ")");
}
}

struct Foo {
int x, y;
string s;
mixin ToStringMixin;
}

void main() {
auto foo = Foo(3, 4, "hello");
writeln(foo);
}

```

Note however that the templated version of toString(W) can be 
difficult to debug in some cases as, if it fails to compile, 
std.format will simply ignore it and not use it while the rest of 
the program compiles successfully.  Any compilation error message 
can be seen by instead attempting to call the method directly, 
e.g. something like `auto a = appender!string; foo.toString(a);`.
I don't use the delegate version personally, but if that's 
already working for you, may as well stick with it.


If you wanted to avoid including a mixin in all of your structs, 
another option is to create a generic templated container struct 
with its own toString:


```d
struct ToStringer(T) {
T t; // Consider T* t
void toString(W)(ref W writer) {
//assert(t !is null);
writer.formattedWrite("%s(\n", T.stringof);
static foreach (idx, field; T.tupleof) {
			writer.formattedWrite("\t%s: %s\n", T.tupleof[idx].stringof, 
t.tupleof[idx]);

}
put(writer, ")");
}
}
auto ToString(T)(ref T t) { // syntactic sugar
return ToStringer!T(t);
}

struct Foo {
int x, y;
string s;
}


void main() {
auto foo = Foo(3, 4, "hello");
//writeln(ToStringer!Foo(foo));
writeln(foo.ToString);
}
```



Re: The One Billion Row Challenge

2024-01-11 Thread bachmeier via Digitalmars-d-learn
On Thursday, 11 January 2024 at 08:57:43 UTC, Christian Köstlin 
wrote:

Did someone already try to do this in dlang?
I guess it will be very hard to beat the java solutions running 
with graalvm!


https://news.ycombinator.com/item?id=38851337

Kind regards,
Christian


The problem with this challenge can be seen in the initial 
comments. Writing the fastest possible program *for a specific 
dataset* is not the same thing as writing the fastest program for 
an arbitrary dataset of that size. And, indeed, the fastest 
program is the one that does nothing but print the answer.


Speed on this task doesn't tell you anything about performance 
with different types/sizes of data or constraints on programmer 
time needed to produce a correct implementation and maintain it 
over time.


Re: How to use ImportC to import WebGPU header

2024-01-11 Thread Sergey via Digitalmars-d-learn

On Wednesday, 10 January 2024 at 23:36:33 UTC, JN wrote:
I would like to use ImportC to automatically import a C header 
into my D project.


It was already done. Use it https://code.dlang.org/packages/wgpu-d
Don't reinvent the wheel :)



Re: Generating custom toString for structs

2024-01-11 Thread cc via Digitalmars-d-learn

On Thursday, 11 January 2024 at 12:45:45 UTC, cc wrote:
I don't use the delegate version personally, but if that's 
already working for you, may as well stick with it.


In retrospect, that delegate version is probably quite a bit 
better.


Re: How to use ImportC to import WebGPU header

2024-01-11 Thread ryuukk_ via Digitalmars-d-learn

You need to use a .c file that include it


--- webgpu.c

```c
#include "webgpu.h"

```


--- app.d

```d
import std.stdio;
import webgpu;

void main()
{
writeln(WGPUBlendFactor_Dst);
}
```


result:

```
$ dmd -run app.d webgpu.c
WGPUBlendFactor_Dst
```