Skip to main content
deleted 5 characters in body
Source Link
rhermans
  • 37.4k
  • 4
  • 61
  • 152

AWith a larger string list

l = With[
   {size = 100},
   MapAt[
    StringJoin[" ", #, " "] &,
    RandomChoice[CharacterRange["a", "z"], {size, size}],
    RandomInteger[{1, size}, {size, 2}]
    ]];

My own @rhermans

First@RepeatedTiming[ 
  StringDelete[" "] /@ l
  ]
(* 0.000750 *)

@murray

First@RepeatedTiming[ 
  StringTrim /@ l
  ]
(* 0.00497 *)

@Coolwater

First@RepeatedTiming[
  StringReplace[#, " " -> ""] & /@ l
  ]
(* 0.000801 *)

@Coolwater operator mode

First@RepeatedTiming[
  StringReplace[" " -> ""] /@ l
  ]
(* 0.000757 *)

@Kuba

First@RepeatedTiming[
  Map[StringTrim, l, {-1}]
  ]
(* 0.0482 *)

A larger string list

l = With[
   {size = 100},
   MapAt[
    StringJoin[" ", #, " "] &,
    RandomChoice[CharacterRange["a", "z"], {size, size}],
    RandomInteger[{1, size}, {size, 2}]
    ]];

My own @rhermans

First@RepeatedTiming[ 
  StringDelete[" "] /@ l
  ]
(* 0.000750 *)

@murray

First@RepeatedTiming[ 
  StringTrim /@ l
  ]
(* 0.00497 *)

@Coolwater

First@RepeatedTiming[
  StringReplace[#, " " -> ""] & /@ l
  ]
(* 0.000801 *)

@Coolwater operator mode

First@RepeatedTiming[
  StringReplace[" " -> ""] /@ l
  ]
(* 0.000757 *)

@Kuba

First@RepeatedTiming[
  Map[StringTrim, l, {-1}]
  ]
(* 0.0482 *)

With a larger string list

l = With[
   {size = 100},
   MapAt[
    StringJoin[" ", #, " "] &,
    RandomChoice[CharacterRange["a", "z"], {size, size}],
    RandomInteger[{1, size}, {size, 2}]
    ]];

My own

First@RepeatedTiming[ 
  StringDelete[" "] /@ l
  ]
(* 0.000750 *)

@murray

First@RepeatedTiming[ 
  StringTrim /@ l
  ]
(* 0.00497 *)

@Coolwater

First@RepeatedTiming[
  StringReplace[#, " " -> ""] & /@ l
  ]
(* 0.000801 *)

@Coolwater operator mode

First@RepeatedTiming[
  StringReplace[" " -> ""] /@ l
  ]
(* 0.000757 *)

@Kuba

First@RepeatedTiming[
  Map[StringTrim, l, {-1}]
  ]
(* 0.0482 *)
Source Link
rhermans
  • 37.4k
  • 4
  • 61
  • 152

A larger string list

l = With[
   {size = 100},
   MapAt[
    StringJoin[" ", #, " "] &,
    RandomChoice[CharacterRange["a", "z"], {size, size}],
    RandomInteger[{1, size}, {size, 2}]
    ]];

My own @rhermans

First@RepeatedTiming[ 
  StringDelete[" "] /@ l
  ]
(* 0.000750 *)

@murray

First@RepeatedTiming[ 
  StringTrim /@ l
  ]
(* 0.00497 *)

@Coolwater

First@RepeatedTiming[
  StringReplace[#, " " -> ""] & /@ l
  ]
(* 0.000801 *)

@Coolwater operator mode

First@RepeatedTiming[
  StringReplace[" " -> ""] /@ l
  ]
(* 0.000757 *)

@Kuba

First@RepeatedTiming[
  Map[StringTrim, l, {-1}]
  ]
(* 0.0482 *)