1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-12-04 16:24:11 +01:00
DataTables/media/unit_testing/performance/large.php

113 lines
3.2 KiB
PHP
Raw Normal View History

2010-08-17 09:42:13 +02:00
<?php
/* MySQL connection */
include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" ); /* ;-) */
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico" />
<title>DataTables example</title>
<style type="text/css" title="currentStyle">
@import "../../css/demo_page.css";
@import "../../css/demo_table.css";
</style>
<script type="text/javascript" language="javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="../../js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
//if ( typeof console != 'undefined' ) {
// console.profile();
//}
Update: Significant update to how sorting is applied internally in DataTables - there is no difference to how the sort is actually done, with the single exception that the -asc and -desc are not depricated in favour of the -pre method only. - With the introduction of the -pre method in DataTables 1.9, the -asc and -desc sorting functions became more or less redundant since they are simple comparisons (all of the complexity is now in the -pre formatting function). As such the call to the -asc / -desc method is overhead that really isn't needed, and this commit introduces a sort function that doesn't call the -asc / -desc methods, instead just doing the comparison itself. In tests, this relatively simple change leads to a performance improvement of around 15% in all browsers (it also has the side benefit of less operations, so IE8- will be able to sort larger tables before flagging up a slow script warning). - We can't just remove the sorting method which will call -asc / -desc though since not all sorting plug-ins will have a -pre method. Therefore, for backwards compatiblity the old sort function (albeit updated for the changed variables) is retained. The backwards compatibality code adds around 300 bytes to the library, but this is an unaccounced change, so backwards compatiblity must be retained. - The old sort method will be removed in v1.11. The -asc and -desc methods are now fully depricated. - Altered the sorting method to flatten the aaSorting array since the introduction of aDataSort in v1.9 required an extra loop in several locations. The functionality is very useful, but the extra loop can be a bit messy and slightly hit performance, so it is now flattened to be a single array (with object information so it makes sense, rather htan array indexes!). - Altered the order of sorting when building _aSortData since it was looking up the same variable smultiple times which really wasn't needed. This is part of a small incremental changes plan for DataTables! There are still a huge number of things to improve in this area, but this is a nice clean up and a nice 15% sorting performance improvement to get us started :-).
2012-09-29 22:25:41 +02:00
var oTable = $('#example').dataTable();
//if ( typeof console != 'undefined' ) {
// console.profileEnd();
//}
Update: Significant update to how sorting is applied internally in DataTables - there is no difference to how the sort is actually done, with the single exception that the -asc and -desc are not depricated in favour of the -pre method only. - With the introduction of the -pre method in DataTables 1.9, the -asc and -desc sorting functions became more or less redundant since they are simple comparisons (all of the complexity is now in the -pre formatting function). As such the call to the -asc / -desc method is overhead that really isn't needed, and this commit introduces a sort function that doesn't call the -asc / -desc methods, instead just doing the comparison itself. In tests, this relatively simple change leads to a performance improvement of around 15% in all browsers (it also has the side benefit of less operations, so IE8- will be able to sort larger tables before flagging up a slow script warning). - We can't just remove the sorting method which will call -asc / -desc though since not all sorting plug-ins will have a -pre method. Therefore, for backwards compatiblity the old sort function (albeit updated for the changed variables) is retained. The backwards compatibality code adds around 300 bytes to the library, but this is an unaccounced change, so backwards compatiblity must be retained. - The old sort method will be removed in v1.11. The -asc and -desc methods are now fully depricated. - Altered the sorting method to flatten the aaSorting array since the introduction of aDataSort in v1.9 required an extra loop in several locations. The functionality is very useful, but the extra loop can be a bit messy and slightly hit performance, so it is now flattened to be a single array (with object information so it makes sense, rather htan array indexes!). - Altered the order of sorting when building _aSortData since it was looking up the same variable smultiple times which really wasn't needed. This is part of a small incremental changes plan for DataTables! There are still a huge number of things to improve in this area, but this is a nice clean up and a nice 15% sorting performance improvement to get us started :-).
2012-09-29 22:25:41 +02:00
var iStart = new Date().getTime();
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnSort( [[ 2, 'asc' ]] );
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnSort( [[ 2, 'asc' ]] );
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnSort( [[ 2, 'asc' ]] );
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnSort( [[ 2, 'asc' ]] );
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnSort( [[ 2, 'asc' ]] );
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnSort( [[ 2, 'asc' ]] );
2010-08-17 09:42:13 +02:00
var iEnd = new Date().getTime();
document.getElementById('output').innerHTML = "Test took "+(iEnd-iStart)+" mS";
2010-08-17 09:42:13 +02:00
} );
</script>
</head>
<body id="dt_example">
<div id="container">
<div class="full_width big">
<i>DataTables</i> performance test - draw
</div>
<div id="output"></div>
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>phone</th>
<th>email</th>
<th>city</th>
<th>zip</th>
<th>state</th>
<th>country</th>
<th>zip2</th>
</tr>
</thead>
<tbody>
<?php
$sQuery = "
SELECT *
FROM testData
LIMIT 2000
";
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
while ( $aRow = mysql_fetch_array( $rResult ) )
{
echo '<tr>';
echo '<td><a href="1">'.$aRow['id'].'</a></td>';
echo '<td>'.$aRow['name'].'</td>';
echo '<td>'.$aRow['phone'].'</td>';
echo '<td>'.$aRow['email'].'</td>';
echo '<td>'.$aRow['city'].'</td>';
echo '<td>'.$aRow['zip'].'</td>';
echo '<td>'.$aRow['state'].'</td>';
echo '<td>'.$aRow['country'].'</td>';
echo '<td>'.$aRow['zip2'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
<div class="spacer"></div>
<div id="footer" style="text-align:center;">
<span style="font-size:10px;">
DataTables &copy; Allan Jardine 2008-2009.
</span>
</div>
</div>
</body>
</html>