Timings (cw)
|shuf0OP |0.00746207|
|shufSyed |0.561942 |
|shufeldo1 |0.707056 |
|shufeldo2 |0.632279 |
|shufcvgmt1 |0.00218898|
|shufcvgmt2 |0.0100496 |
|shufkglr7 |0.00446289|
|shufkglr8 |0.863815 |
|shufvindobona|0.00143314|
|shufkglr10 |0.00182783|
Just in case, let me reproduce the way I coded it, in case something is unsatisfactory please let me know (or edit the post accordingly, it is cw after all).
funtest[f_, n_, ss_] :=
Module[{a, b},
Mean[
First[AbsoluteTiming[f[#, Array[a, Length[#]], Array[b, n - Length[#]]]]]&/@ss
]
]
n = 10000
ss = Table[Union@RandomSample[Range[n], RandomInteger[n]], {100}];
shuf0OP[s_, a_, b_] :=
With[{n = Length[a] + Length[b]},
With[{t = Complement[Range[n], s]},
Module[{l = Range[n]},
Do[l[[s[[k]]]] = a[[k]], {k, Length[s]}];
Do[l[[t[[k]]]] = b[[k]], {k, Length[t]}];
l
]
]
]
shufSyed[s_, a_, b_] :=
Fold[Insert[#1, First@#2, Last@#2] &, b, Transpose[{a, s}]]
shufeldo1[s_, a_, b_] :=
Module[{ds = CreateDataStructure["ExtensibleVector"]},
Scan[ds["Append", #] &, b];
ds["Insert", ##] & @@@ Transpose[{a, s}];
Normal@ds
]
shufeldo2[s_, a_, b_] :=
b // RightComposition @@ MapThread[Insert, {a, s}]
shufcvgmt1[s_, a_, b_] :=
With[{n = Length[a] + Length[b]},
Module[{list = Range@n},
list[[s]] = a; list[[Complement[Range[n], s]]] = b;
list
]
]
shufcvgmt2[s_, a_, b_] :=
With[{n = Length[a] + Length[b]},
ReplacePart[Range@n,
Thread /@ {s -> a, Complement[Range@n, s] -> b} // Flatten]
]
ClearAll[sA]
sA = Module[{i$ = Complement[Range@Length@Join@##2, #]},
SparseArray[{# -> #2, i$ -> #3}]] &;
shufkglr7[s_, a_, b_] := Normal@sA[s, a, b]
shufkglr8[s_, a_, b_] :=
Module[{bb = b},
Normal[SparseArray[s -> a, {Length@Join[a, b]}]] /.
0 :> Last[bb = RotateLeft@bb]
]
shufvindobona[s_, a_, b_] :=
#[[Ordering@Join[s, Complement[Range@Length@#, s]]]]&@Join[a, b]
ClearAll[pA]
pA = Module[{ab$ = Join @ ##2, p$},
p$ = Join[#, Complement[Range @ Length @ ab$, #]];
Permute[ab$, p$]
] &;
shufkglr10[s_, a_, b_] := pA[s, a, b]
TableForm@
Table[{f, funtest[f, n, ss]},
{f, {
shuf0OP,
shufSyed,
shufeldo1,
shufeldo2,
shufcvgmt1,
shufcvgmt2,
shufkglr7,
shufkglr8,
shufvindobona,
shufkglr10
}
}
]