Jump to content
Taylorh140

A simple method to buffer input

Recommended Posts

I find myself frequently looking for a good pattern for collecting a pool of array elements until they reach a certain size and then removing the oldest elements first. I have used very stupid methods like a bunch of feedback nodes being fed into an build array node. But today I thought up one that I really enjoyed and I thought that I'd share it. Its a simple pattern and no crossing wires :). Perhaps someone has thought of something better, if so don't hesitate to share.

Example_VI_BD.png

Share this post


Link to post
Share on other sites

I've never done performance testing but I've always used rotate and replace to avoid the build array. It should be very easy to make a malleable VI out of it to further reduce block diagram clutter.

For example:

new last.png

Edited by infinitenothing
  • Like 1

Share this post


Link to post
Share on other sites

There is also the Data Queue VI in the PtByPt palettes.  Personally, I found a fixed sized lossy queue to work very well as a circular buffer.

Share this post


Link to post
Share on other sites

Very neat and postage stamp sized.  There are apparently lots of different ways to perform this and I have yet another way that I've been doing.  This is part of my Force 1D Array Min or Max Size VIM that is part of my array package found here.  I am curious what is the fastest, and under what conditions one works better than another.

Force 1D Array Min or Max Size.png

 

Also somewhat relevant is my Circular Buffer XNodes I made here.  This one uses the shifting method, but tried to be a little more efficient with things like not shifting if it wasn't needed, and if a shift was needed to keep the shifted data so a consecutive read wouldn't require a shift or split and build.

Share this post


Link to post
Share on other sites

So I did a quick run, and I probably need to state that the above methods cannot really be compared apples to apples. Partially for the following reasons:

  • Some methods only support one element at a time input. If you need to enter 1000 pts at once these methods will probably be slower and involve more operations.
  • Some methods like the circular buffer are much more useful in certain situations like where the buffer is needed in different loops or are acquired at different rates. 

here are numbers for single point(one element at a time) inputs:

How long does it take to process 10000 input samples with a buffer size of 1000 on my computer?: 

  • Taylorh140 => 8.28579 ms 
  • infinitenothing => 2.99063 ms  (looks like shifting wins)
  • Data Queue Pt-by-pt => 9.03695 ms (I expected that this would beat mine)
  • hooovahh Circular Buffer => 8.7936 ms (Nearly as good as mine and uses DVR)

I would consider all these to be winners, except maybe the Data Queue pt-by-pt (but it is available by default which gives it a slight edge), Perhaps ill have to do another test where inputs are more than one sample.

Note: if you want to try the source you'll need the circular buffer xnodes installed.

buffer.zip

  • Like 1

Share this post


Link to post
Share on other sites

How often you write new elements versus how often you have to read the whole array may also skew the preference given to one scheme. For example, if you write often a single element, just replacing it in place at (i mod N) may be efficient, whereas the readout which involves an array copy may be left with a more expensive solution. This is my go at it, not double checked, may be bugged.

w.pngr.png

  • Like 1

Share this post


Link to post
Share on other sites
On ‎11‎/‎14‎/‎2017 at 7:08 PM, crossrulz said:

Personally, I found a fixed sized lossy queue to work very well as a circular buffer.

That is what I typically use... Generally I wrap in a class.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.