Jump to content

Shuffle string


Wouter

Recommended Posts

  • 1 month later...

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
Link to comment

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

Link to comment

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)).

Link to comment

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

Link to comment

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.