Created
August 14, 2017 11:15
-
-
Save ninjarobot/4b2fdb901bf1a5b6427db6062153572b to your computer and use it in GitHub Desktop.
GC scenario when producing a lot of large string buffers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
private static String buildBigString (int numStrings) { | |
StringBuffer sb = new StringBuffer(); | |
for(int i = 0; i < numStrings; i++) { | |
sb.append("12345678"); | |
sb.append(","); | |
} | |
return sb.toString(); | |
} | |
public static void main(String[] args) { | |
long totalLength = 0L; | |
for(int i = 0; i < 10000; i++) { | |
String s = buildBigString(100000); | |
totalLength = totalLength + s.length(); | |
} | |
System.out.format("Built 100000 strings, total of %d length.\n", totalLength); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let buildBigString numStrings = | |
let sb = System.Text.StringBuilder() | |
for i in 1..numStrings do | |
sb.Append("12345678") |> ignore | |
sb.Append(",") |> ignore | |
sb.ToString () | |
[<EntryPoint>] | |
let main argv = | |
let mutable totalLength = 0L | |
for i in 1..10000 do | |
let s = buildBigString 100000 | |
totalLength <- totalLength + int64 s.Length | |
printfn "Built 100000 strings, total of %d length." totalLength | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment