You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/08/29 05:55:10 UTC

[GitHub] [spark] LuciferYang commented on pull request #37701: [SPARK-40252][SQL] Replace `Stream.collect(Collectors.joining(delimiter))` with `StringJoiner` Api

LuciferYang commented on PR #37701:
URL: https://github.com/apache/spark/pull/37701#issuecomment-1229810248

   I do the following test:
   
   ```
       return v + " IN (" + list.stream().collect(Collectors.joining(", ")) + ")";
   
   
   Replcace `Stream.collect(Collectors.joining(delimiter))` to StringJoiner Api
   
   
   
   
     private def testJoinString(input: Array[String], valuesPerIteration: Int): Unit = {
   
       val benchmark = new Benchmark(
         s"Test join String Array with input size ${input.length}",
         valuesPerIteration,
         output = output)
   
       benchmark.addCase("Use Arrays.steam api no prefix, suffix") { _: Int =>
         for (_ <- 0L until valuesPerIteration) {
           // code: "(" + Arrays.stream(input).collect(Collectors.joining(", ")) + ")"
           TestApis.joinStreamApiNoPreSuffix(input)
         }
       }
   
       benchmark.addCase("Use Arrays.steam api with prefix, suffix") { _: Int =>
         for (_ <- 0L until valuesPerIteration) {
           // code: Arrays.stream(input).collect(Collectors.joining(", ", "(", ")"));
           TestApis.joinStreamApiWithPreSuffix(input)
         }
       }
   
       benchmark.addCase("Use String joiner api") { _: Int =>
         for (_ <- 0L until valuesPerIteration) {
           // code:
           // StringJoiner joiner = new StringJoiner(", ", "(", ")");
           // for (String s : input) {
           //  joiner.add(s);
           // }
           // joiner.toString();
           return joiner.toString();
           TestApis.stringJoinerApi(input)
         }
       }
   
       benchmark.addCase("Use String join api") { _: Int =>
         for (_ <- 0L until valuesPerIteration) {
           // "(" + String.join(", ", input) + ")"
           TestApis.stringJoinApi(input)
         }
       }
   
       benchmark.run()
     }
   
     private def testJoinString(input: List[String], valuesPerIteration: Int): Unit = {
   
       import scala.collection.JavaConverters._
   
       val benchmark = new Benchmark(
         s"Test join String List with input size ${input.length}",
         valuesPerIteration,
         output = output)
   
   
       val list = input.asJava
   
       benchmark.addCase("Use Arrays.steam api no prefix, suffix") { _: Int =>
         for (_ <- 0L until valuesPerIteration) {
           // "(" + input.stream().collect(Collectors.joining(", ")) + ")"
           TestApis.joinStreamApiNoPreSuffix(list)
         }
       }
   
       benchmark.addCase("Use Arrays.steam api with prefix, suffix") { _: Int =>
         for (_ <- 0L until valuesPerIteration) {
           // input.stream().collect(Collectors.joining(", ", "(", ")"))
           TestApis.joinStreamApiWithPreSuffix(list)
         }
       }
   
       benchmark.addCase("Use String joiner api") { _: Int =>
         for (_ <- 0L until valuesPerIteration) {
           // StringJoiner joiner = new StringJoiner(", ", "(", ")");
           // for (String s : input) {
           //   joiner.add(s);
           // }
           TestApis.stringJoinerApi(list)
         }
       }
   
       benchmark.addCase("Use String join api") { _: Int =>
         for (_ <- 0L until valuesPerIteration) {
           // "(" + String.join(", ", input) + ")"
           TestApis.stringJoinApi(list)
         }
       }
   
       benchmark.run()
     }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org