StringTemplate
introduced in version 10 is very convenient in constructing formatted data. However, it seems to have a huge performance issue.
Consider this example:
data = RandomInteger[{1, 100}, {20000, 3}];
data1 =
StringRiffle[
Apply[StringTemplate["<`1`,`2`,`3`>,`1`,`2`,`3`"], data, {1}],
",\n"]; // AbsoluteTiming
(* {6.54397, Null} *)
data2 =
StringRiffle[
Apply["<" <> ToString[#1] <> "," <> ToString[#2] <> "," <>
ToString[#3] <> ">" <> "," <> ToString[#1] <> "," <>
ToString[#2] <> "," <> ToString[#3] &, data, {1}],
",\n"]; // AbsoluteTiming
(* {0.186368, Null} *)
data1 == data2
(* True *)
We see that although the StringTemplate
version is short and clean, it is 35X slower than the ordinary StringJoin
version.
Do you consider this a bug?
StringTemplate
? Why no one cares about the performance? The performance issue still remains to date with 12.2 ! $\endgroup$