Algorithm Question
I have some stupid questions....
 Why would program 1 run a lot faster than program 2? Can someone explain?
If I change the sample_size to be a larger one, program 2 will my
browser freeze!!
 What is the optimum value (1024 in this case) to use?
Program 1:

int sample_size = 5120; // 5K
for (i=0; i < (sample_size/1024); i++) {
my_buffer = "";
for (j=1; j<=1024; j++) {
my_buffer += "a";
}
my_data += my_buffer;
}
Program 2:

int sample_size = 5120; // 5K
for (i=0; i < sample_size; i++) {
my_data += "a";
}
