February 13, 2014 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Monday, 10 February 2014 at 10:41:06 UTC, Russel Winder wrote:
> On Mon, 2014-02-10 at 09:16 +0000, Gary Willoughby wrote:
>> On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap wrote:
>> > (disclaimer: I'm new around here)
>> > Is it possible to cycle backwards? If not, what's the best approach?
>>
>> import std.algorithm;
>> import std.array;
>> import std.range;
>> import std.stdio;
>>
>> void main(string[] args)
>> {
>> auto data = [1,2,3];
>>
>> assert(data.cycle.take(5).array == [1,2,3,1,2]);
>> assert(data.retro.cycle.take(5).array == [3,2,1,3,2]);
>> }
>
> This is why people should be using D instead of C++! This really needs
> to get onto the D website somewhere.
how efficient is ufcs? It seems like it would be very slow in
general and way better to manually do the code. I wonder if
anyone has done any tests?
|
February 13, 2014 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frustrated | On Thursday, 13 February 2014 at 20:56:32 UTC, Frustrated wrote:
> how efficient is ufcs? It seems like it would be very slow in
> general and way better to manually do the code. I wonder if
> anyone has done any tests?
LDC and GDC are pretty darn good at inlining these UFCS chains, but the yielded machine code might be slightly suboptimal. In any case, you should use a profiler instead of making decisions based on some intuitive feelings which might easily be wrong. (don't underestimate the efforts put into GCC & LLVM backends!)
|
Copyright © 1999-2021 by the D Language Foundation