-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
54 lines (51 loc) · 7.45 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!doctype html>
<html>
<head><meta name="build" content="20140328174343" />
<meta charset="utf-8" />
<title>Speed tests</title>
<link rel="stylesheet" type="text/css" media="all" href="style.css?EsZSFD-08SdHtdGdYlnSLw" />
</head>
<body>
<script type="text/javascript" src="script.js?y7P5OixjiOR2d9xYdwaZtg"></script>
<script type="text/javascript" src="script1.js?NYwIaMcI-QYBYpbnvw6hag"></script>
<a href="https://github.com/lahmatiy/lib-compare"><img style="position:absolute;top:0;right:0;border:0" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" /></a>
<div style="position:relative" id="tests">
<label style="margin:1em 0;display:block"><input type="checkbox" id="autorun" checked /> Auto-run test on select</label>
</div>
<div style="overflow:hidden;clear:both">
<hr />
<div id="time"> </div>
<hr />
<div style="float:left;width:40%;margin:0 20px">
Init:
<textarea id="init" rows="5"></textarea>
Code:
<textarea id="code" rows="5"></textarea>
<select id="count">
<option value="1000">1 000</option>
<option value="10000" selected>10 000</option>
<option value="100000">100 000</option>
<option value="1000000">1 000 000</option>
</select>
<button onclick="run()">run</button>
</div>
<div style="overflow:hidden">
Compiled:
<div id="compiled" class="Basis-SyntaxHighlight" style="border:1px solid #000;min-height:4em;white-space:pre">
</div>
</div>
</div>
<script type="text/javascript">basis.require("./0.js");basis.require("./2.js");basis.require("./4.js");var benchmark=basis.require("./5.js"),highlight=basis.require("./6.js").highlight,COUNT=1E4,res_;basis.require("./6.js").useStyle();function testCode(a,b){$("#init").val(b||"");$("#code").val(a||"");$("#compiled").html("");$("#autorun")[0].checked&&run()}
function run(a){var b=$("#count").val();a=$("#init").val().trim()||"";a="var a_ = [], time_;\n"+(a?a+"\n":"")+"\ntime_ = benchmark.time();\n\nfor (var i = 0; i < count; i++){\n "+$("#code").val().trim().replace(/\r/g,"").replace(/\n/g,"\n ")+"\n}\n\ntime_ = benchmark.time(time_);\n\nreturn [a_, time_];";try{var c=new Function("count",a)}catch(d){$("#compiled").text("Compilation error: "+d);return}$("#compiled").html(highlight(basis.utils.info.fn(c).body.trim(),"js",{noLineNumber:!0}));$("#time").html("Running...");
res_=null;try{c(Math.min(1E3,b))}catch(f){$("#time").html("Execution error: "+f);return}setTimeout(function(){res_=c(b);$("#time").html(basis.number.group(b)+" runs in <b>"+res_[1]+"</b>ms")},100)}
$(function(){function a(a,b,c){return $("<button>"+g+"</button>").click(function(){testCode(b,c)})[0]}for(var b=[{name:"Empty config",init:"var data = {};",tests:{"native":"new Object()","basis.data":"new basis.data.Object({ data: data })","basis.entity":{init:"var Type = basis.entity.createType({ all: false });",code:"Type(data)"},backbone:"new Backbone.Model(data)",ember:"Ember.Object.create(data)"}},{name:"3 data fields",init:"var data = { p1: 1, p2: 2, p3: 3 };",tests:{"native":"new Object(data)",
"basis.data":"new basis.data.Object({ data: data })","basis.entity":{init:"var Type = basis.entity.createType({ all: false }, basis.object.keys(data).reduce(function(res, key){ res[key] = basis.fn.$self; return res; }, {}));",code:"Type(data)"},backbone:"new Backbone.Model(data)",ember:"Ember.Object.create(data)"}},{name:"10 data fields",init:"var data = { p1: 1, p2: 2, p3: 3, p4: 4, p5: 5, p6: 6, p7: 7, p8: 8, p9: 9, p10: 10 };",tests:{"native":"new Object(data)","basis.data":"new basis.data.Object({ data: data })",
"basis.entity":{init:"var Type = basis.entity.createType({ all: false }, basis.object.keys(data).reduce(function(res, key){ res[key] = basis.fn.$self; return res; }, {}));",code:"Type(data)"},backbone:"new Backbone.Model(data)",ember:"Ember.Object.create(data)"}},{name:"20 data fields",init:"var data = { p1: 1, p2: 2, p3: 3, p4: 4, p5: 5, p6: 6, p7: 7, p8: 8, p9: 9, p10: 10, p11: 1, p12: 2, p13: 3, p14: 4, p15: 5, p16: 6, p17: 7, p18: 8, p19: 9, p20: 10 };",tests:{"native":"new Object(data)","basis.data":"new basis.data.Object({ data: data })",
"basis.entity":{init:"var Type = basis.entity.createType({ all: false }, basis.object.keys(data).reduce(function(res, key){ res[key] = basis.fn.$self; return res; }, {}));",code:"Type(data)"},backbone:"new Backbone.Model(data)",ember:"Ember.Object.create(data)"}},{name:"1 listeners on create",init:"",tests:{basis:{init:"var HANDLER = { foo: function(){} };",code:"new basis.data.Object({ handler: HANDLER })"},backbone:{init:"var foo = function(){};\nvar bar = function(){};\nvar baz = function(){};\nvar Foo = Backbone.Model.extend({ initialize: function(){\n this.on('foo', foo);\n}});",
code:"new Foo()"}}},{name:"1 listeners after create",init:"",tests:{basis:{init:"var HANDLER = { foo: function(){} };",code:"var o = new basis.data.Object();\no.addHandler(HANDLER);"},backbone:{init:"var foo = function(){};",code:"var o = new Backbone.Model();\no.on('foo', foo);"},ember:{init:"var foo = function(){};",code:"var o = Ember.Object.create();\no.addObserver('foo', null, foo);"}}},{name:"2 listeners after create",init:"",tests:{basis:{init:"var HANDLER = { foo: function(){}, bar: function(){} };",
code:"var o = new basis.data.Object();\no.addHandler(HANDLER);"},backbone:{init:"var foo = function(){};\nvar bar = function(){};",code:"var o = new Backbone.Model();\no.on('foo', foo);\no.on('bar', bar);"},ember:{init:"var foo = function(){};\nvar bar = function(){};",code:"var o = Ember.Object.create();\no.addObserver('foo', null, foo);\no.addObserver('bar', null, bar);"}}},{name:"3 listeners after create",init:"",tests:{basis:{init:"var HANDLER = { foo: function(){}, bar: function(){}, baz: function(){} };",
code:"var o = new basis.data.Object();\no.addHandler(HANDLER);"},backbone:{init:"var foo = function(){};\nvar bar = function(){};\nvar baz = function(){};",code:"var o = new Backbone.Model();\no.on('foo', foo);\no.on('bar', bar);\no.on('baz', baz);"},ember:{init:"var foo = function(){};\nvar bar = function(){};\nvar baz = function(){};",code:"var o = Ember.Object.create();\no.addObserver('foo', null, foo);\no.addObserver('bar', null, bar);\no.addObserver('baz', null, baz);"}}},{name:"10 data fields, 1 listener",
init:"var data = { p1: 1, p2: 2, p3: 3, p4: 4, p5: 5, p6: 6, p7: 7, p8: 8, p9: 9, p10: 10 };",tests:{"basis.data":{init:"var HANDLER = { foo: function(){} };",code:"var o = new basis.data.Object({ data: data });\no.addHandler(HANDLER);"},"basis.entity":{init:"var HANDLER = { foo: function(){} };\nvar Type = basis.entity.createType({ all: false }, basis.object.keys(data).reduce(function(res, key){ res[key] = basis.fn.$self; return res; }, {}));",code:"var o = Type(data);\no.addHandler(HANDLER);"},
backbone:{init:"var foo = function(){};",code:"var o = new Backbone.Model(data);\no.on('foo', foo);"},ember:{init:"var foo = function(){};",code:"var o = Ember.Object.create(data);\no.addObserver('foo', null, foo);"}}}],c=0;c<b.length;c++){var d=b[c],f=$('<div class="testButtons"><h3>'+d.name+"</h3></div>")[0],g;for(g in d.tests){var e=d.tests[g],h=[d.init||""];"string"!=typeof e&&(h.push(e.init||""),e=e.code);f.appendChild(a(g,e,h.filter(Boolean).join("\n")))}$("#tests").append(f)}})</script>
</body>
</html>