SELECT ev1.event_point,ev1.event_date, (select event_date from test_events where ev1.event_point = event_point and event_type = (CASE WHEN ev1.event_type = 1 THEN 2 ELSE 1 END) and event_date > ev1.event_date limit 1) as end_date FROM test_events as ev1 WHERE ev1.event_date BETWEEN '2012-1-1' AND '2012-1-31' AND ev1.event_type IN (1 , 2)
SELECT event_point,SUM(TIMESTAMPDIFF(HOUR,event_date,end_date)) FROM ( SELECT ev1.event_point,ev1.event_date, (select event_date from test_events where ev1.event_point = event_point and event_type = (CASE WHEN ev1.event_type = 1 THEN 2 ELSE 1 END) and event_id > ev1.event_id limit 1) as end_date FROM test_events as ev1 WHERE ev1.event_date BETWEEN '2012-1-1' AND '2012-1-31' AND ev1.event_type IN (1 , 2) ) report GROUP BY event_point
<?php $summary[] = array(); $count = 5000; for($i1=0;$i1<$count;++$i1){ $summary[$i1] = $i1; } $t = microtime(true); for($i1=0;$i1<$count;++$i1){ for($i2=0;$i2<$count;++$i2){ if("5468735354987"!="654654655465"){ $summary[$i1] = $i1*$i2; } } } echo "<li>time: ".(microtime(true)-$t).' ms</li>'; $sum = 0; for($i1=0;$i1<$count;++$i1){ $sum = $sum + $summary[$i1]; } echo "<li>test["+$sum+"]"; ?>
<?php $summary[] = array(); $count = 5000; for($i1=0;$i1<$count;++$i1){ $summary[$i1] = $i1; } $t = microtime(true); for($i1=0;$i1<$count;++$i1){ for($i2=0;$i2<$count;++$i2){ if("5468735354987"!="654654655465"){ $summary[$i1] = $i1*$i2; } } } echo "<li>time: ".(microtime(true)-$t).' ms</li>'; $sum = 0; for($i1=0;$i1<$count;++$i1){ $sum = $sum + $summary[$i1]; } echo "<li>test["+$sum+"]"; ?>
<% count = 5000 Dim summary(5000) for i1=0 to count summary(i1) = i1 next t = timer() for i1=0 to count for i2=0 to count if ("5468735354987"<>"654654655465") then summary(i1) = i1*i2 end if next next response.write timer()-t sum = 0 for i1=0 to count sum = sum + summary(i1) next response.write "sum:"&sum response.write "<br>test-wsc<br>" Dim obj Set obj = GetObject("script:"&Server.MapPath("test.wsc")) Call obj.run() %>
<?xml version="1.0"?> <component> <?component error="true" debug="true"?> <registration description="test" progid="test" version="0.1" classid="{13e4b1b3-c698-40ea-8450-9cbc9b33ef03}" > </registration> <public> <method name="run"/> </public> <implements type="ASP" id="ASP"/> <script language="VBScript"> <![CDATA[ Function run() count = 5000 Dim summary(5000) for i1=0 to count summary(i1) = i1 next Dim t : t = timer() for i1=0 to count for i2=0 to count if ("5468735354987"<>"654654655465") then summary(i1) = i1*i2 end if next next response.write (timer()-t) sum = 0 for i1=0 to count sum = sum + summary(i1) next response.write "sum:"&sum End Function ]]> </script> </component>
count = 5000 Dim summary(5000) for i1=0 to count summary(i1) = i1 next t = timer() for i1=0 to count for i2=0 to count if ("5468735354987"<>"654654655465") then summary(i1) = i1*i2 end if next next msgbox (timer()-t) sum = 0 for i1=0 to count sum = sum + summary(i1) next msgbox "sum:"&sum
<%@ Page validateRequest="false" Debug="true" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Diagnostics" %> <%@ Import Namespace="System.Threading" %> <script language="C#" runat="server"> public void Page_Load(Object sender, EventArgs E) { int count = 5000; int[] summary = new int[5000]; for (int i1 = 0; i1 < count; i1++) { summary[i1] = i1; } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i1 = 0; i1 < count; ++i1) { for (int i2 = 0; i2 < count; ++i2) { if("5468735354987"!="654654655465"){ summary[i1] = i1*i2; } } } stopwatch.Stop(); Response.Write("<li>time: " + (stopwatch.ElapsedMilliseconds) + " ms</li>"); long sum = 0; for (int i1 = 0; i1 < count; ++i1) { sum = sum + summary[i1]; } Response.Write("<li>test[" + sum + "]"); } </script>
var fs = require('fs'), http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); summary = new Array(); count = 5000; for(var i1=0;i1<count;++i1){ summary[i1] = i1; } var start = new Date().getTime(); for(var i1=0;i1<count;++i1){ for(var i2=0;i2<count;++i2){ if("5468735354987"!="654654655465"){ summary[i1] = i1*i2; } } } res.write("<li>time: "+(new Date().getTime() - start)+" ms"); var sum = 0; for(i1=0;i1<count;++i1){ sum = sum + summary[i1]; } res.write("<li>sum: ["+sum+"]"); res.end(); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');
<!DOCTYPE html> <html> <head> <script> function testClear() { var summary = []; var count = 5000; for(var i1=0;i1<count;++i1){ summary[i1] = i1; } var start = new Date().getTime(); for(var i1=0;i1<count;++i1){ for(var i2=0;i2<count;++i2){ if("5468735354987"!=="654654655465"){ summary[i1] = i1*i2; } } } document.getElementById("testClear").innerHTML = "time: "+(new Date().getTime() - start)+" ms"; var sum = 0; for(i1=0;i1<count;++i1){ sum = sum + summary[i1]; } alert("sum: ["+sum+"]"); } </script> </head> <body> <p><a href="#" onclick="testClear();"><div>test clear:<span id='testClear'></span></div></a></p> </body> </html>
<!DOCTYPE html> <html> <head> <script> function testClear() { var summary = []; var count = 5000; for(var i1=0;i1<count;++i1){ summary[i1] = i1; } var start = new Date().getTime(); for(var i1=0;i1<count;++i1){ for(var i2=0;i2<count;++i2){ if("5468735354987"!=="654654655465"){ summary[i1] = i1*i2; } } } document.getElementById("testClear").innerHTML = "time: "+(new Date().getTime() - start)+" ms"; var sum = 0; for(i1=0;i1<count;++i1){ sum = sum + summary[i1]; } alert("sum: ["+sum+"]"); } </script> </head> <body> <p><a href="#" onclick="testClear();"><div>test clear:<span id='testClear'></span></div></a></p> </body> </html>
<!DOCTYPE html> <html> <head> <script type='text/javascript' src='jquery.js'></script> <script> function test() { $('#test').html('loading...'); $.get('test_ajax.html', function(data) { $('#test').html(data); }); } </script> </head> <body> <p><a href="#" onclick="test();"><div>test jquery ajax:<span id='test'></span></div></a></p> </body> </html>
<!DOCTYPE html> <html> <head> <script type='text/javascript' src='prototype.js'></script> <script> function testFn() { $('test').update('loading...'); new Ajax.Updater('test','test_ajax.html', { method: 'get', asynchronous:true, evalScripts:true, onSuccess: function(transport) { $('test').update('in process...'); }, onFailure: function(transport) { alert("Error"); } }); } </script> </head> <body> <p><a href="#" onclick="testFn();"><div>test prototype ajax:<span id='test'></span></div></a></p> </body> </html>
<script> summary = new Array(); count = 5000; for(i1=0;i1<count;++i1){ summary[i1] = i1; } var start = new Date().getTime(); for(var i1=0;i1<count;++i1){ for(var i2=0;i2<count;++i2){ if("5468735354987"!="654654655465"){ summary[i1] = i1*i2; } } } document.getElementById("test").innerHTML = "time: "+(new Date().getTime() - start)+" ms"; var sum = 0; for(i1=0;i1<count;++i1){ sum = sum + summary[i1]; } alert("sum: ["+sum+"]"); </script>
<% 'time: 13.58594 'time: 58.01563 Set FSO = CreateObject("Scripting.FileSystemObject") Set File = FSO.GetFile(Server.MapPath("test_replace.txt")) Set Reader = FSO.OpenTextFile(File, 1,False) buffer = Reader.ReadAll Reader.Close t = timer() For rec=1 to 10 For col=0 to 100 buffer = Replace(buffer,"{{"&rec&":"&col&"}}","-|-") Next Next response.write "time: "&timer()-t response.write "<hr>" response.write buffer %>
<%@ Page validateRequest="false" Debug="true" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Diagnostics" %> <%@ Import Namespace="System.Threading" %> <script language="C#" runat="server"> public void Page_Load(Object sender, EventArgs E) { //time: 8736 ms //time:[1and1] 16183 ms string buffer = File.ReadAllText(Server.MapPath("test_replace.txt")); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int rec = 0; rec < 10; rec++) { for (int col = 0; col < 100; col++) { buffer = buffer.Replace("{{" + rec + ":" + col + "}}", "-|-"); } } stopwatch.Stop(); Response.Write("<li>time: " + (stopwatch.ElapsedMilliseconds) + " ms</li>"); Response.Write(buffer); } </script>
<?php //time: 4.570 ms //time:ks.ua 10.3491752148 ms //time:servmax 5.7612838745117 ms $buffer = file_get_contents('test_replace.txt'); $t = microtime(true); for($rec=0;$rec<10;++$rec){ for($col=0;$col<100;++$col){ $buffer = str_replace( "{{".$rec.":".$col."}}","-|-", $buffer ); } } echo "time: ".(microtime(true)-$t).' ms'; echo "<hr>"; echo $buffer; ?>
var fs = require('fs'), http = require('http'); http.createServer(function (req, res) { fs.readFile('test_replace.txt', function (err, data) { data = String(data); if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return; } res.writeHead(200, {'Content-Type': 'text/html'}); var start = new Date().getTime(); for (var rec = 0; rec < 10; ++rec) { for (var col = 0; col < 100; ++col) { data = data.replace(new RegExp( "{{" + rec + ":" + col + "}}", "g" ), "-|-"); } } console.log(new Date().getTime()-start); res.end(data); }); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');
CREATE TABLE test_events ( event_id int IDENTITY (1, 1), event_type int, event_point int, event_date datetime ) -------------- ALTER TABLE [test_events] ADD CONSTRAINT [IDX_event_type] DEFAULT ((1)) FOR [event_type] GO ALTER TABLE [test_events] ADD CONSTRAINT [IDX_event_point] DEFAULT ((1)) FOR [event_point] GO ALTER TABLE [test_events] ADD CONSTRAINT [IDX_event_date] DEFAULT (NULL) FOR [event_date] GO -------------- DECLARE @counter bigint = 0; DECLARE @event_type smallint = 1; -------------- BEGIN TRANSACTION; WHILE @counter < 1000000 BEGIN IF @event_type=1 SET @event_type=2 ELSE SET @event_type=1 INSERT INTO test_events (event_type,event_point,event_date) VALUES (@event_type,ROUND(5 * RAND() + 100,0),DATEADD(MINUTE,@counter*10,'1/1/2011')) SET @counter = @counter + 1 END COMMIT TRAN; -------------- SET NOCOUNT ON SELECT event_point,SUM(DATEDIFF(hour,event_date,end_date)) FROM ( SELECT ev1.event_point,ev1.event_date, (select top 1 event_date from test_events where ev1.event_point = event_point and event_type = (CASE WHEN ev1.event_type = 1 THEN 2 ELSE 1 END) and event_id > ev1.event_id) as end_date FROM test_events as ev1 WHERE ev1.event_date BETWEEN '2012-1-1' AND '2012-1-31' AND ev1.event_type IN (1 , 2) ) report GROUP BY event_point
Source: https://habr.com/ru/post/162885/
All Articles