Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Created August 14, 2017 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninjarobot/4b2fdb901bf1a5b6427db6062153572b to your computer and use it in GitHub Desktop.
Save ninjarobot/4b2fdb901bf1a5b6427db6062153572b to your computer and use it in GitHub Desktop.
GC scenario when producing a lot of large string buffers
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);
}
}
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