| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- local count = 100000;
- local start = os.clock();
- for(var k=0; k < count; ++k){
- var text = "Hello";
- text += " "
- text += "World!";
- text += "Hello";
- text += " "
- text += "World!";
- text += "Hello";
- text += " "
- text += "World!";
- text += "Hello";
- text += " "
- text += "World!";
- text += "Hello";
- text += " "
- text += "World!";
- text += "Hello";
- text += " "
- text += "World!";
- text += "Hello";
- text += " "
- text += "World!";
- text += "Hello";
- text += " "
- text += "World!";
- }
- print("String concatenation with + took:", os.clock()-start);
- start = os.clock();
- for(var k=0; k < count; ++k){
- var text = "Hello" + " " + "World!" + "Hello" + " " + "World!" + "Hello" + " " + "World!" + "Hello" +
- " " + "World!" + "Hello" + " " + "World!" + "Hello" + " " + "World!" + "Hello" + " " + "World!" +
- "Hello" + " " + "World!";
- }
- print("String concatenation with + took:", os.clock()-start);
- start = os.clock();
- for(var k=0; k < count; ++k){
- var buffer = [];
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- var text = buffer.concat();
- }
- print("String concatenation with array.concat1 took:", os.clock()-start);
- var buffer = array(24);
- start = os.clock();
- for(var k=0; k < count; ++k){
- buffer.clear();
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- buffer.push("Hello");
- buffer.push(" ");
- buffer.push("World!");
- var text = buffer.concat();
- }
- print("String concatenation with array.concat2 took:", os.clock()-start);
- print(type(buffer))
- var push = buffer.push.bindenv(buffer);
- print(type(push), type(push.getenv()), type(push.getenv().ref()))
- {
- buffer.clear();
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- print(buffer.concat());
- }
- start = os.clock();
- for(var k=0; k < count; ++k){
- buffer.clear();
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- push("Hello");
- push(" ");
- push("World!");
- var text = buffer.concat();
- }
- print("String concatenation with array.concat3 took:", os.clock()-start);
- buffer.resize(24);
- start = os.clock();
- for(var k=0; k < count; ++k){
- var i = 0;
- buffer.clear();
- buffer.resize(24);
- buffer[i++] = "Hello";
- buffer[i++] = " ";
- buffer[i++] = "World!";
- buffer[i++] = "Hello";
- buffer[i++] = " ";
- buffer[i++] = "World!";
- buffer[i++] = "Hello";
- buffer[i++] = " ";
- buffer[i++] = "World!";
- buffer[i++] = "Hello";
- buffer[i++] = " ";
- buffer[i++] = "World!";
- buffer[i++] = "Hello";
- buffer[i++] = " ";
- buffer[i++] = "World!";
- buffer[i++] = "Hello";
- buffer[i++] = " ";
- buffer[i++] = "World!";
- buffer[i++] = "Hello";
- buffer[i++] = " ";
- buffer[i++] = "World!";
- buffer[i++] = "Hello";
- buffer[i++] = " ";
- buffer[i++] = "World!";
- var text = buffer.concat();
- }
- print("String concatenation with array2.concat took:", os.clock()-start);
- start = os.clock();
- for(var k=0; k < count; ++k){
- var i = -1;
- buffer.clear();
- buffer.resize(24);
- buffer[++i] = "Hello";
- buffer[++i] = " ";
- buffer[++i] = "World!";
- buffer[++i] = "Hello";
- buffer[++i] = " ";
- buffer[++i] = "World!";
- buffer[++i] = "Hello";
- buffer[++i] = " ";
- buffer[++i] = "World!";
- buffer[++i] = "Hello";
- buffer[++i] = " ";
- buffer[++i] = "World!";
- buffer[++i] = "Hello";
- buffer[++i] = " ";
- buffer[++i] = "World!";
- buffer[++i] = "Hello";
- buffer[++i] = " ";
- buffer[++i] = "World!";
- buffer[++i] = "Hello";
- buffer[++i] = " ";
- buffer[++i] = "World!";
- buffer[++i] = "Hello";
- buffer[++i] = " ";
- buffer[++i] = "World!";
- var text = buffer.concat();
- }
- print("String concatenation with array3.concat took:", os.clock()-start);
- var ary_set = buffer.set.bindenv(buffer);
- start = os.clock();
- for(var k=0; k < count; ++k){
- var i = -1;
- buffer.clear();
- buffer.resize(24);
- ary_set(++i, "Hello");
- ary_set(++i, " ");
- ary_set(++i, "World!");
- ary_set(++i, "Hello");
- ary_set(++i, " ");
- ary_set(++i, "World!");
- ary_set(++i, "Hello");
- ary_set(++i, " ");
- ary_set(++i, "World!");
- ary_set(++i, "Hello");
- ary_set(++i, " ");
- ary_set(++i, "World!");
- ary_set(++i, "Hello");
- ary_set(++i, " ");
- ary_set(++i, "World!");
- ary_set(++i, "Hello");
- ary_set(++i, " ");
- ary_set(++i, "World!");
- ary_set(++i, "Hello");
- ary_set(++i, " ");
- ary_set(++i, "World!");
- ary_set(++i, "Hello");
- ary_set(++i, " ");
- ary_set(++i, "World!");
- var text = buffer.concat();
- }
- print("String concatenation with array4.concat took:", os.clock()-start);
- start = os.clock();
- for(var k=0; k < count; ++k){
- var i = -1;
- buffer.clear();
- buffer.resize(24);
- buffer.set(++i, "Hello");
- buffer.set(++i, " ");
- buffer.set(++i, "World!");
- buffer.set(++i, "Hello");
- buffer.set(++i, " ");
- buffer.set(++i, "World!");
- buffer.set(++i, "Hello");
- buffer.set(++i, " ");
- buffer.set(++i, "World!");
- buffer.set(++i, "Hello");
- buffer.set(++i, " ");
- buffer.set(++i, "World!");
- buffer.set(++i, "Hello");
- buffer.set(++i, " ");
- buffer.set(++i, "World!");
- buffer.set(++i, "Hello");
- buffer.set(++i, " ");
- buffer.set(++i, "World!");
- buffer.set(++i, "Hello");
- buffer.set(++i, " ");
- buffer.set(++i, "World!");
- buffer.set(++i, "Hello");
- buffer.set(++i, " ");
- buffer.set(++i, "World!");
- var text = buffer.concat();
- }
- print("String concatenation with array5.concat took:", os.clock()-start);
|