|
<P><FONT face=宋体 size=2> 影响性能测试报告测试的源代码</FONT></P>
<P><FONT face=宋体 size=2> ——文章不错,可供相关人员参考学习</FONT></P>
<P><FONT face=宋体 size=2>主题:影响性能测试的源代码(数据库)</FONT></P>
<P><FONT face=宋体 size=2>关键词:测试报告、数据库、性能分析、性能测试、源代码</FONT></P>
<P><FONT face=宋体 size=2></FONT> </P>
<P><BR>CapabilityForConnection 主运行程序,读取配置文件init.properties、reference.properties初始化参数。调用POOLTEST(一次完整的测试用例),计算其平均时间与使用连接数package com.cea.repository.test;</P>
<P>import org.apache.commons.logging.LogFactory;<BR>import org.apache.commons.logging.Log;<BR>import java.util.Properties;<BR>import java.io.FileInputStream;<BR>import java.io.InputStream;</P>
<P>public class CapabilityForConnection {<BR> private static Log log = LogFactory.getLog(CapabilityForConnection.class);<BR> /**<BR> * 计算一次测试所消耗的时间<BR> */<BR> public static long times = 0;<BR> /**<BR> * 连接数<BR> */<BR> public static long psize = 0;</P>
<P> public static void main(String[] args) throws Exception {<BR> /**<BR> * 运行的次数<BR> */<BR> int size = 1;<BR> /**<BR> * 见POOLTEST说明<BR> */<BR> int execsum = 0;<BR> /**<BR> * 见POOLTEST说明<BR> */<BR> int opencon = 0;<BR> /**<BR> * execsum对应properties的命名<BR> */<BR> String execs = null;<BR> /**<BR> * opencon对应properties的命名<BR> */<BR> String openc = null;</P>
<P> long sumtime = 0;<BR> Properties prop = initProperty("reference.properties");<BR> Properties init = initProperty("init.properties");</P>
<P> if (init.size() > 0) {<BR> Object o = init.get("init");<BR> size = Integer.parseInt(o.toString());<BR> execs = init.get("name0").toString();<BR> openc = init.get("name1").toString();<BR> }</P>
<P> for (int i = 0; i < prop.size() / 2; i++) {<BR> execsum = Integer.parseInt(prop.getProperty(execs + i).toString());<BR> opencon = Integer.parseInt(prop.getProperty(openc + i).toString());<BR> sumtime = 0;<BR> psize = 0;<BR> log.info("第" + (i + 1) + "组数据:");<BR> log.info("并发应用数:" + execsum + " 模拟连接数:" + opencon);</P>
<P> String[] reference = {"" + execsum, "" + opencon};<BR> for (int j = 0; j < size; j++) {<BR> times = 0;<BR> PoolTest.main(reference);<BR> sumtime += times;<BR> }<BR> log.info("第" + (i + 1) + "组数据共执行" + size + "次;平均耗时为:" +<BR> sumtime / (size * execsum) + "毫秒");<BR> log.info("平均使用" + psize / size + "个连接");</P>
<P> }<BR> }</P>
<P> private static Properties initProperty(String filename) throws Exception {<BR> InputStream is = new FileInputStream(filename);<BR> Properties prop = new Properties();<BR> prop.load(is);<BR> return prop;</P>
<P> }<BR>}<BR></P>
[ 本帖最后由 Jon 于 2007-5-23 13:02 编辑 ] |
|