On Tuesday, 22 April 2014 at 15:25:04 UTC, monarch_dodra wrote:
Yeah, that's because join actually works on "RoR, R", rather
than "R, E". This means if you feed it a "string[], string",
then it will actually iterate over individual *characters*. Not
only that, but since you are using char[], it
On Tuesday, 22 April 2014 at 11:41:41 UTC, Jay Norwood wrote:
Wow, joiner is much slower than join. Such a small choice can
make this big of a difference. Not at all expected, since the
lazy calls, I thought, were considered to be more efficient.
This is with ldc2 -O2.
Yeah, that's becaus
On Tuesday, 22 April 2014 at 05:05:30 UTC, Jay Norwood wrote:
On Monday, 21 April 2014 at 08:26:49 UTC, monarch_dodra wrote:
The two "key" points here, first, is to avoid using appender.
Second, instead of having two buffer: "" and "**\n",
and two do two "slice copies", to only have 1 b
Wow, joiner is much slower than join. Such a small choice can
make this big of a difference. Not at all expected, since the
lazy calls, I thought, were considered to be more efficient.
This is with ldc2 -O2.
jay@jay-ubuntu:~/ec_ddt/workspace/diamond/source$ ./main
1>/dev/null
brad: time:
On Monday, 21 April 2014 at 08:26:49 UTC, monarch_dodra wrote:
The two "key" points here, first, is to avoid using appender.
Second, instead of having two buffer: "" and "**\n",
and two do two "slice copies", to only have 1 buffer "
*", and to do 1 slice copy, and a single '\n' w
On Monday, 21 April 2014 at 00:11:14 UTC, Jay Norwood wrote:
So this printDiamonde2b example had the fastest time of the
solutions, and had similar times on all three builds. The ldc2
compiler build is performing best in most examples on ubuntu.
void printDiamonde2b(in uint N)
{
uint N2 =
On Tuesday, 25 March 2014 at 08:42:30 UTC, monarch_dodra wrote:
Interesting. I'd have thought the "extra copy" would be an
overall slowdown, but I guess that's not the case.
I installed ubuntu 14.04 64 bit, and measured some of these
examples using gdc, ldc and dmd on a corei3 box. The ex
void main(){
import std.stdio,std.range,std.algorithm,std.conv;
auto m=10.iota.map!(_=>readln.split.to!(int[]));
m.map!sum.chain(m.transposed.map!sum).reduce!max.write;
}
It used to work, but with the latest changes I think I have
broken it.
Bye,
bearophile
This corrects the parallel example range in the second foreach.
Still slow.
void printDiamonde2cpa(in uint N)
{
size_t N2 = N/2;
char p[] = uninitializedArray!(char[])(N2+N);
p[0..N2] = ' ';
p[N2..$] = '*';
char nl[] = uninitializedArray!(char[])(1);
nl[] = '\n';
ch
On Wednesday, 26 March 2014 at 04:47:48 UTC, Jay Norwood wrote:
This is a first attempt at using parallel, but no improvement
oops. scratch that one. I tested a pointer to the wrong function.
This is a first attempt at using parallel, but no improvement in
speed on a corei7. It is about 3x slower than the prior
versions. Probably the join was not a good idea. Also, no
foreach_reverse for the parallel, so it requires extra
calculations for the reverse index.
void printDiamonde2
On Tuesday, 25 March 2014 at 15:31:12 UTC, monarch_dodra wrote:
I love how D can achieve *great* performance, while still
looking readable and maintainable.
Yes, I'm pretty happy to see the appender works well. The
parallel library also seems to work very well in my few
experiences with it.
On Tuesday, 25 March 2014 at 12:30:37 UTC, Jay Norwood wrote:
These are times on ubuntu. printDiamond3 was slower than
printDiamond.
Hum... Too bad :/
I was able to improve my first "printDiamon" by having a single
slice that contains spaces then stars, and make writeln's of that.
It gave (
These are times on ubuntu. printDiamond3 was slower than
printDiamond.
brad: time: 12387[ms]
printDiamond1: time: 373[ms]
printDiamond2: time: 722[ms]
printDiamond3: time: 384[ms]
jay1: time: 62[ms]
sergei: time: 3918[ms]
jay2: time: 28[ms]
diamondShape: time: 2725[ms]
printDiamond: time: 19[ms
Interesting. I'd have thought the "extra copy" would be an
overall slowdown, but I guess that's not the case.
I also tried your strategy of adding '\n' to the buffer, but I
was getting some bad output on windows. I'm not sure why "\n\n"
works though. On *nix, I'd have also expected a doub
On Tuesday, 25 March 2014 at 02:25:57 UTC, Jay Norwood wrote:
not through yet with the diamond. This one is a little faster.
Appending the newline to the stars and calculating the slice
backward from the end would save a w.put for the newlines ...
probably faster. I keep looking for a way to
These were times on ubuntu. I may have printed debug build times
previously, but these are dmd release build. I gave up trying to
figure out how to build ldc on ubuntu. The dmd one click
installer is much appreciated.
brad: time: 12425[ms]
printDiamond1: time: 380[ms]
printDiamond2: time: 72
not through yet with the diamond. This one is a little faster.
Appending the newline to the stars and calculating the slice
backward from the end would save a w.put for the newlines ...
probably faster. I keep looking for a way to create a dynamic
array of a specific size, filled with the in
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
This is a somewhat common little exercise:
if you like similar puzzles, here is another:
Write a program that expects a 10-by-10 matrix from standard
input. The program should compute sum of each row and each column
and print the
Very nice example. I'll test on ubuntu later.
On windows ...
D:\diamond\diamond\diamond\Release>diamond 1> nul
brad: time: 19544[ms]
printDiamond1: time: 1139[ms]
printDiamond2: time: 1656[ms]
printDiamond3: time: 663[ms]
jay1: time: 455[ms]
sergei: time: 11673[ms]
jay2: time: 411[ms]
diamondS
On Sunday, 23 March 2014 at 18:28:18 UTC, Jay Norwood wrote:
On Sunday, 23 March 2014 at 17:30:20 UTC, bearophile wrote:
The task didn't ask for a computationally efficient solution
:-) So you are measuring something that was not optimized for.
So there's lot of variance.
Bye,
bearophile
These were the times on ubuntu 64 bit dmd. I added diamondShape,
which is slightly modified to be consistent with the others ..
just removing the second parameter and doing the writeln calls
within the function, as the others have been done. This is still
with dmd. I've downloaded ldc.
Als
On Sunday, 23 March 2014 at 17:30:20 UTC, bearophile wrote:
The task didn't ask for a computationally efficient solution
:-) So you are measuring something that was not optimized for.
So there's lot of variance.
Bye,
bearophile
Yes, this is just for my own education. My builds are using
Jay Norwood:
A problem with the previous brad measurement is that his
solution creates a diamond of size 2n+1 for an input of n.
Correcting the size input for brad's function call, and
re-running, I get this. So the various solutions can have
overhead computation time of 40x difference, dep
A problem with the previous brad measurement is that his solution
creates a diamond of size 2n+1 for an input of n. Correcting the
size input for brad's function call, and re-running, I get this.
So the various solutions can have overhead computation time of
40x difference, depending on the i
I converted the solution examples to functions, wrote a test to
measure each 100 times with a diamond of size 1001. These are
release build times. timon's crashed so I took it out. Maybe I
made a mistake copying ... have to go back and look.
D:\diamond\diamond\diamond\Release>diamond 1>nul
Hmmm, looks like stderr.writefln requires format specs, else it
omits the additional parameters. (not so on derr.writefln)
stderr.writefln("time: %s%s",sw.peek().msecs, "[ms]");
D:\diamond\diamond\diamond\Release>diamond 1>nul
time: 16[ms]
time: 44[ms]
On Saturday, 22 March 2014 at 14:41:48 UTC, Jay Norwood wrote:
The computation times of different methods can differ a lot.
How do you suggest to measure this effectively without the
overhead of the write and writeln output? Would a count of
11 and stubs like below be reasonable, or wou
On 03/22/2014 06:03 PM, Jay Norwood wrote:
> derr.writefln("time: ", sw.peek().msecs, "[ms]");
Cool. stderr should work too:
stderr.writefln(/* ... */);
Ali
I decided to redirect stdout to nul and print the stopwatch
messages to stderr.
So, basically like this.
import std.stdio;
import std.datetime;
import std.cstream;
StopWatch sw;
sw.start();
measured code
sw.stop();
derr.writefln("time: ", sw.peek().msecs, "[ms]");
Then, windows results compa
The computation times of different methods can differ a lot.
How do you suggest to measure this effectively without the
overhead of the write and writeln output? Would a count of
11 and stubs like below be reasonable, or would there be
something else that would prevent the optimizer fr
On Friday, 21 March 2014 at 13:59:27 UTC, Vladimir Panteleev
wrote:
On Friday, 21 March 2014 at 12:32:58 UTC, Sergei Nosov wrote:
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
This is a somewhat common little exercise: Write a function
that takes the size of a diamond and produ
On Friday, 21 March 2014 at 12:32:58 UTC, Sergei Nosov wrote:
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
This is a somewhat common little exercise: Write a function
that takes the size of a diamond and produces a diamond of
that size.
When printed, here is the output for s
On Friday, 21 March 2014 at 12:32:58 UTC, Sergei Nosov wrote:
Probably, the most boring way is
foreach(i; 0..N)
{
foreach(j; 0..N)
write(" *"[i + j >= N/2 && i + j < 3*N/2 && i - j <=
N/2 && j - i <= N/2]);
writeln;
}
A single foreach(i; 0..N*N) is more boring!
This one calculates, then outputs subranges of the ba and sa char
arrays.
int n = 11;
int blanks[];
blanks.length = n;
int stars[];
stars.length = n;
char ba[];
ba.length = n;
ba[] = ' '; // fill full ba array
char sa[];
sa.length = n;
sa[] = '*'; // fill full sa array
int c = n/2; // center of
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
This is a somewhat common little exercise: Write a function
that takes the size of a diamond and produces a diamond of that
size.
When printed, here is the output for size 11:
*
***
*
***
*
*
On Friday, 21 March 2014 at 00:31:58 UTC, bearophile wrote:
This is a somewhat common little exercise: Write a function
Bye,
bearophile
I like that replicate but easier for me to keep track of the
counts if I work from the center.
int blanks[];
blanks.length = n;
int stars[];
stars.length
On 03/20/2014 02:25 PM, Ali Çehreli wrote:
Write a function that takes
the size of a diamond and produces a diamond of that size.
I have learned a lot, especially the following two:
1) chain'ing iotas is an effective way of producing non-monotonic number
intervals (and more).
2) There is s
Ali Çehreli:
This is a somewhat common little exercise: Write a function
that takes the size of a diamond and produces a diamond of that
size.
When printed, here is the output for size 11:
*
***
*
***
*
***
*
***
*
***
*
On Thursday, 20 March 2014 at 22:46:53 UTC, Ali Çehreli wrote:
On 03/20/2014 03:03 PM, Brad Anderson wrote:
> I'm not entirely happy with it but:
I am not happy with my attempt either. :)
>void main()
>{
> import std.algorithm, std.range, std.stdio, std.conv;
>
> enum length
On 03/20/2014 03:48 PM, Timon Gehr wrote:
On 03/20/2014 10:25 PM, Ali Çehreli wrote:
This is a somewhat common little exercise: Write a function that takes
the size of a diamond and produces a diamond of that size.
When printed, here is the output for size 11:
*
***
*
***
On 03/20/2014 02:52 PM, Chris Williams wrote:
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
What interesting, boring, efficient, slow, etc. ways are there?
Ali
Well one of the more convoluted methods that I can think of would be to
define a square as a set of four vectors, ro
On 03/20/2014 10:25 PM, Ali Çehreli wrote:
This is a somewhat common little exercise: Write a function that takes
the size of a diamond and produces a diamond of that size.
When printed, here is the output for size 11:
*
***
*
***
*
***
*
On 03/20/2014 03:03 PM, Brad Anderson wrote:
> I'm not entirely happy with it but:
I am not happy with my attempt either. :)
>void main()
>{
> import std.algorithm, std.range, std.stdio, std.conv;
>
> enum length = 5;
> auto rng =
> chain(iota(length), iota(length
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
What interesting, boring, efficient, slow, etc. ways are there?
Ali
I'd be interested in seeing a solution using "iota", and the
currently proposed "each" or "tee". A quick protype to draw a
triangle would be:
iota(0, n).each!(
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
This is a somewhat common little exercise: Write a function
that takes the size of a diamond and produces a diamond of that
size.
When printed, here is the output for size 11:
*
***
*
***
*
*
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
What interesting, boring, efficient, slow, etc. ways are there?
Ali
Well one of the more convoluted methods that I can think of would
be to define a square as a set of four vectors, rotate 45
degrees, and then create a rasterizer
On 03/20/2014 02:30 PM, Justin Whear wrote:
> What's the appropriate output for an even number?
Great question! :) Size must be odd. I have this in my function:
enforce(size % 2,
format("Size cannot be an even number. (%s)", size));
Ali
On Thu, 20 Mar 2014 14:25:02 -0700, Ali Çehreli wrote:
> This is a somewhat common little exercise: Write a function that takes
> the size of a diamond and produces a diamond of that size.
>
> When printed, here is the output for size 11:
>
> *
> ***
> *
>***
> *
This is a somewhat common little exercise: Write a function that takes
the size of a diamond and produces a diamond of that size.
When printed, here is the output for size 11:
*
***
*
***
*
***
*
***
*
***
*
What interesting
50 matches
Mail list logo