8
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ I would consider it worth reporting. $\endgroup$
    – chuy
    Aug 30, 2016 at 13:32
  • 1
    $\begingroup$ FYI: reported with [CASE:3699358]. $\endgroup$ Aug 30, 2016 at 13:45
  • $\begingroup$ Have you received any reply from the support? $\endgroup$ Mar 19, 2017 at 12:42
  • $\begingroup$ No body use StringTemplate? Why no one cares about the performance? The performance issue still remains to date with 12.2 ! $\endgroup$
    – matheorem
    Jul 5, 2022 at 14:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.