Jump to content
Sign in to follow this  
Wouter

Shuffle string

Recommended Posts

VI Name:

String shuffle

Total VIs:

1

Description:

This VI shuffles a string.

Note:

-

Blockdiagram:

gallery_17774_56_3325.png

Code:

StrShuffle.zip

What are you thoughts on this VI?

  • Would you like to see such a function in OpenG?
  • Can you optimize the code?
  • In which package should it be included?
  • Should it be rejected?

Edited by Wouter

Share this post


Link to post
Share on other sites

The Keyed Sort is quite a slow way to perform the shuffle operation. The built-in riffle function is the fastest way. My next choice would have been the following:

http://forums.ni.com...light/true#M462

Unfortunately, that creature has been returned to its cage.

That leaves me with performing the good, old Fisher-Yates-Knuth shuffle, and I would probably just use the byte array instead of the char array.

post-26690-0-56993700-1318021749_thumb.p

The section where I find a random integer between i and N-1 could certainly be replaced with the new OpenG function. Probably a modest hit in performance.

The section labelled 'Knuth Shuffle' can be adapted very easily to any datatype.

KnuthShuffleString.vi

Edited by Darin

Share this post


Link to post
Share on other sites

Riffle. I was banging my head against my desk trying to remember that name.

Here's my take on it. I benchmarked it using 1KB of Lorem Ipsum text on my Quad Core i5 and it happy chewed up 25% of each processor. But it averaged < 1ms over 250k runs. Maybe it's late on a Friday, but something seems wrong here.

post-13461-0-90713000-1318026974.png

post-13461-0-90177900-1318026975.png

Edit: 70KB in 6ms. Dang.

post-13461-0-46670600-1318035510.png

RiffleString.vi

RiffleStringBenchmark.vi

Share this post


Link to post
Share on other sites

The argument against Riffle is that it is not in the base package. That is why I considered alternatives. The fastest way if you want to use Riffle.vi is to live with the coercions and Riffle the byte array from the string directly. It would be nice if NI would provide a U8 instance of Riffle.vi.

(Wow, I got to say Riffle four times (now five)).

Share this post


Link to post
Share on other sites

The argument against Riffle is that it is not in the base package. That is why I considered alternatives. The fastest way if you want to use Riffle.vi is to live with the coercions and Riffle the byte array from the string directly. It would be nice if NI would provide a U8 instance of Riffle.vi.

(Wow, I got to say Riffle four times (now five)).

Aww, crap, you're right. What a shame.

On the other hand, your implementation didn't trail by very much:

post-13461-0-20261300-1318280218.png

:thumbup1:

KnuthShuffleStringBenchmark.vi

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.

Sign in to follow this  

×
×
  • Create New...

Important Information

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