asp代码效率求教II,用将代码用js写成类来调用是否会比不这么写代码快?还有其他的请进来看..200分求教~进来看啊~~

xiwanghope 2005-12-15 10:44:57
1.用将代码用js写成类来调用是否会比不这么写代码快?

2.用recordset查询数据库是否有要求的值,没有就addnew,有就update,这样效率高吗?如果实现这样的功能,有其他什么更好的办法吗?

3.用js封装类的时候,编码上有什么需要注意的地方吗?怎么写才会让代码执行效率更高~


希望大家多多帮忙~~~在下给分不手软的~~~~
...全文
147 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
js的代码不好改成组件,反正我不用js写服务端代码
jspadmin 2005-12-15
  • 打赏
  • 举报
回复
自己测试效率吧。在程序开始的地方设置个timer,计算下代码总共执行时间,同时通过任务管理器查看内存占用和CPU占用白分比和时间,如果差别不太明显,可以通过循环方式来多次执行代码,那样差别就放大了。比如要测试不同查询数据库方式的执行速度,可以试着反复查询1000次,然后看执行时间和CPU占用率。理论上的东西实际未必就是那样。
KimSoft 2005-12-15
  • 打赏
  • 举报
回复
用将代码用js写成类来调用是否会比不这么写代码快?

这个不好说,还是看你代码了,不过理论上是慢了(但不会慢很多)。但是封装性强了。能写成类最好写成类。
MYLiao 2005-12-15
  • 打赏
  • 举报
回复
用prototype定义的类方法是一个接口,就像是一个接口类,
你只需要关心如何去实现它这个接口的方法是如何实现的,
因此它是可以编辑的,你可以根据你的具体业务逻辑随时修改它的实现方法
KimSoft 2005-12-15
  • 打赏
  • 举报
回复
都是解释执行,能快多少呢。只能说JavaScript基于对象的功能强些。
真要快的话,用JSP或ASP.Net
MYLiao 2005-12-15
  • 打赏
  • 举报
回复
用 prototype 属性提供对象的类的一组基本功能。
对象的新实例“继承”赋予该对象原型的操作。
并且,它是可编辑的,肯定是这种好,它载入了面向对象的概念。
MYLiao 2005-12-15
  • 打赏
  • 举报
回复
主要编辑的一点代码如下:
function _DG__onrowenter()
{ // output a single row <TR> for current record
if (this._objDataSource.EOF)
return;

var hilite = '';
if (this.hiliteAttributes.length &&
this._markPos == this._objDataSource.absolutePosition)
hilite = this.hiliteAttributes;

var strHTML = '<TR>\n';
if (this.rowAttributes.length)
{ // apply row attributes to <TR>
var nRow = this._rowCount % this.rowAttributes.length;
strHTML = '<TR ' + hilite + ' ' + this.rowAttributes[nRow] + '>\n';
}
else
strHTML = '<TR ' + hilite + '>\n';

// output <TD> for each column in row
var nCols = this.colData.length;
for (var nCol=0; nCol < nCols; nCol++)
{
// apply column attributes to <TD>
if (nCol < this.colAttributes.length)
// act.asp用于对文件进行重定向并进行一定的设置,
// path是所要导向的文件路径,后加myfile、是对文件路径进行简单的保密和错乱,在使用时要定义其文件名称,比如:
// dim dirfilename
// dirfilename="a.asp" ''或者 dirfilename="filename/a.asp"
// id中加入'520'字串是为了对absolutePosition进行一定的保密
strHTML += '<TD ' + hilite + ' ' + this.colAttributes[nCol] + '><a href="../act.asp?path=myfile' + dirfilename + '&id=520' + this._objDataSource.absolutePosition + '">';
else
strHTML += '<TD><a href="#">';

// determine format per data column
if (typeof(this.colFormat[nCol]) != 'undefined')
{ // use column format
strHTML += this.colFormat[nCol];
}
else if (this.rowFormat.length)
{ // use row format
var nRow = this._rowCount % this.rowFormat.length;
strHTML += this.rowFormat[nRow];
}

strHTML += eval(this.colData[nCol]);
strHTML += '</a></TD>\n';
}

strHTML += '</TR>\n';
Response.write(strHTML);
this._rowCount++;
}
xiwanghope 2005-12-15
  • 打赏
  • 举报
回复
再问一下,你用prototype定义的类方法,和那种内嵌的定义方法,那个效率高些?
MYLiao 2005-12-15
  • 打赏
  • 举报
回复
太长了,不好发。
yopy 2005-12-15
  • 打赏
  • 举报
回复
JS封装的要好一些!
MYLiao 2005-12-15
  • 打赏
  • 举报
回复
接上面的:
function _DG__Prototype()
{
_bDGPrototypeCalled = 1;

//private members
_DataGrid.prototype.pageSize = 0;
_DataGrid.prototype.hasPageNumber = false;
_DataGrid.prototype.allColumns = false;
_DataGrid.prototype.displayHeader = true;
_DataGrid.prototype.navbarAlignment = 'center';
_DataGrid.prototype.hiliteAttributes = ''; // attributes applied to row of the current record
_DataGrid.prototype.maintainState = true;

_DataGrid.prototype._bVisible = true;
_DataGrid.prototype._objPageNavbar = null;
_DataGrid.prototype._objRecordNavbar = null;

//public methods
_DataGrid.prototype.show = _DG_show;
_DataGrid.prototype.hide = _DG_hide;
_DataGrid.prototype.isVisible = _DG_isVisible;
_DataGrid.prototype.getPagingNavbar = _DG_getPagingNavbar;
_DataGrid.prototype.getRecordsetNavbar = _DG_getRecordsetNavbar;
_DataGrid.prototype.bindAllColumns = _DG_bindAllColumns;

//private methods
_DataGrid.prototype.getDataSource = _DG_getDataSource;
_DataGrid.prototype.setDataSource = _DG_setDataSource;
_DataGrid.prototype.showPageNavbar = _DG_showPageNavbar;
_DataGrid.prototype.showRecordNavbar = _DG_showRecordNavbar;
_DataGrid.prototype.anchor = _DG_anchor;
_DataGrid.prototype.display = _DG_display;

_DataGrid.prototype._fireEvent = _EM__fireEvent;
_DataGrid.prototype._preserveState = _DG__preserveState;
_DataGrid.prototype._restoreState = _DG__restoreState;
_DataGrid.prototype._onrowenter = _DG__onrowenter;

thisPage.registerMethod('_DG__selectRow',_DG__selectRow);

//scope implementation in _DG__Prototype function
function _DG_show()
{ this._bVisible = true; }

function _DG_hide()
{ this._bVisible = false; }

function _DG_isVisible()
{ return this._bVisible }

function _DG_getPagingNavbar()
{ return this._objPageNavbar; }

function _DG_getRecordsetNavbar()
{ return this._objRecordNavbar; }

function _DG_bindAllColumns()
{ this.allColumns = true; }

function _DG_getDataSource()
{ return this._objDataSource; }

function _DG_setDataSource(objDataSource)
{
if (typeof(objDataSource) == 'object')
this._objDataSource = objDataSource;
}

function _DG_showPageNavbar(nMask,nAlignment)
{
this._objPageNavbar = CreateRecordsetNavbar(this.name + '_PageNavbar',null,null);
this._objPageNavbar.setAlignment(nAlignment);
this._objPageNavbar.setButtonStyles(nMask);
this._objPageNavbar.pageSize = this.pageSize;
this._objPageNavbar.updateOnMove = false;
this._objPageNavbar.setDataSource(this._objDataSource);
return this._objPageNavbar;
}

function _DG_showRecordNavbar(nMask,nAlignment)
{
this._objRecordNavbar = CreateRecordsetNavbar(this.name + '_RecordNavbar',null,null);
this._objRecordNavbar.setAlignment(nAlignment);
this._objRecordNavbar.setButtonStyles(nMask);
this._objRecordNavbar.pageSize = 1;
this._objRecordNavbar.updateOnMove = false;
this._objRecordNavbar.setDataSource(this._objDataSource);
return this._objRecordNavbar;
}

function _DG_anchor(strText)
{
var nIndex = this._objDataSource.absolutePosition;
if (Number(nIndex) > 0)
{
if (typeof(strText) == 'undefined' || strText == '')
strText = nIndex;
return '<a href="JavaScript:thisPage.invokeMethod(' +
"''" +
",'_DG__selectRow'," +
"new Array('" + this.name + "','" + nIndex + "'))" +
'">' + strText + '</a>';
}
return '';
}
MYLiao 2005-12-15
  • 打赏
  • 举报
回复
<SCRIPT RUNAT=SERVER LANGUAGE="JavaScript">
// ************************************************************************
// MSL : Microsoft Scripting Libary
// Visual InterDev 6.0 DataGrid Object for ASP
// Copyright 1998 Microsoft Corporation. All Rights Reserved.
// Modify by MYLiao 2003-10-12
// ************************************************************************
function CreateDataGrid(strName,funcInit,objParent)
{
if (typeof(strName) == 'string' && strName != '')
{
var objDataGrid = new _DataGrid(strName,objParent);
eval(strName + ' = objDataGrid');

objDataGrid._funcInit = funcInit;
thisPage.advise(PAGE_ONINIT,strName + '._restoreState()');
return objDataGrid;
}
return null;
}

function _DataGrid(strName,objParent)
{
if (typeof(_bDGPrototypeCalled) == 'undefined')
_DG__Prototype();

// public members
this.id = strName;
this.name = strName;

// private members
// see the display method description below
this.tableAttributes = ''; // <TABLE tableAttributes>
this.headerAttributes = ''; // <TR headerAttributes>
this.headerWidth = new Array; // <TH> width attributes
this.headerFormat = ''; // <TH>headerFormat colHeader[nCol]</TH>
this.colHeader = new Array;
this.rowAttributes = new Array; // <TR rowAttributes[nRow]>
this.rowFormat = new Array;
this.colData = new Array; // <TD colAttributes[nCol]>rowFormat[nRow] colData[nCol]</TD>
this.colAttributes = new Array; // OR
this.colFormat = new Array; // <TD colAttributes[nCol]>colFormat[nCol] colData[nCol]</TD>

this._objDataSource = null;
this._markPos = 0;
}
MYLiao 2005-12-15
  • 打赏
  • 举报
回复
1、用JS封装的类调用的话,肯定比用VBS封装的类快;
2、判断的话,最好不要用组件Recordset去更新或者插入,
用组件做这些事情,很耗内存,也影响速度和效率,把这些事情交给存储过程解决,速度会提高很多;
3、稍后给你发个我自己编辑的ASP组件DataGrid的JS封装源代码。
KimSoft 2005-12-15
  • 打赏
  • 举报
回复
一、效率不一定,但代码重用性肯定提高了。
二、用SQL更好些。
三、你的编程的经验了。在不断的写代码中积累。
xiwanghope 2005-12-15
  • 打赏
  • 举报
回复
刚才测试了一下,觉得用prototype跟不用基本上看不出差别。

针对access来说,除用rescordset没什么别的办法,测试了一下,效率基本属于可接受范围。

谢谢各位的指点,结

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧