您的位置:首页 > 其它

(test-it.sh)

2010-12-15 17:48 169 查看
#!/bin/sh

# Verify whether the directory of JavaScript Cases is inputted.

if [ $# -lt 1 ];then

echo "Please specify the directory of JavaScript Cases!"

exit

fi

# Verify whether the inputted directory exists.

if [ ! -d $1 ];then

echo "$1 does not exist!"

exit

fi

CURRENT_DIR=`dirname $0`

JSC_JIT=`echo "${CURRENT_DIR}/jsc_jit"`

JSC_NO_JIT=`echo "${CURRENT_DIR}/jsc_no_jit"`

# Verify whether the jsc with jit exists

if [ ! -f ${JSC_JIT} ];then

echo "JSC with JIT does not exist!"

exit

fi

# Verify whether the jsc without jit exists

if [ ! -f ${JSC_NO_JIT} ];then

echo "JSC without JIT does not exist!"

exit

fi

SUM=0

OK=0

NG=0

LOG=it-test.log

> $LOG

# Search each *.js file in the specified directory.

JS_FILES=`find $1 -name "*.vert"`

# Test each JS file with jsc_jit and jsc_no_jit.

echo "" | tee -a $LOG

DATE=`date`

echo "Test time:$DATE" | tee -a $LOG

for JS in $JS_FILES

do

BYTE_CODE_SIZE=0

MACHINE_CODE_SIZE=0

MAX_MACHINE_CODE_SIZE=0

echo "Testing ${JS} ..." | tee -a $LOG

echo -e "var stime = new Date();/n" > case.js

cat ${JS} >> case.js

echo -e "var etime = new Date();/nprint(/"Duration is:/", etime-stime);/n" >> case.js

# Get executive time of case with jsc_jit

${JSC_JIT} case.js &> tmp

# Get the executive time

TIME_JIT=`cat tmp | grep "Duration" | awk -F: '{print $2}'`

# Get the compilation time

compile_times=`cat tmp | grep "Compilation Time(ms)" | awk -F: '{print $2}'`

loop=`echo $compile_times | wc -l`

all_compile_time=0

# Get the sum of all time

for compile_time in $compile_times

do

all_compile_time=`expr ${all_compile_time} + ${compile_time}`

done

# Calculate byte code size

SIZES=`cat tmp | grep "Byte Code Size(byte):" | awk -F: '{print $2}'`

for SIZE in ${SIZES}

do

BYTE_CODE_SIZE=`expr ${BYTE_CODE_SIZE} + ${SIZE}`

done

# Calculate machine code size

SIZES=`cat tmp | grep "Machine Code Size(byte):" | awk -F: '{print $2}'`

for SIZE in ${SIZES}

do

MACHINE_CODE_SIZE=`expr ${MACHINE_CODE_SIZE} + ${SIZE}`

if [ ${SIZE} -gt ${MAX_MACHINE_CODE_SIZE} ]

then

MAX_MACHINE_CODE_SIZE=${SIZE}

fi

done

# Get memory usage

MEM_USAGE=`cat tmp | grep "heap total" | awk '{print $6 $9 $12}'`

HEAP_TOTAL=`echo $MEM_USAGE | awk -F, '{print $1}'`

HEAP_PEAK=`echo $MEM_USAGE | awk -F, '{print $2}'`

STACK_PEAK=`echo $MEM_USAGE | awk -F, '{print $3}'`

# Get executive time of case with jsc_no_jit

TIME_NO_JIT=`${JSC_NO_JIT} case.js | grep "Duration" | awk -F: '{print $2}'`

echo "Running Time (ms)" | tee -a $LOG

printf "Used JIT :%8d/n" ${TIME_JIT} | tee -a $LOG

printf "Unused JIT :%8d/n" ${TIME_NO_JIT} | tee -a $LOG

printf "Compiling Time (ms) :%8d/n" ${all_compile_time} | tee -a $LOG

printf "Byte Code Size(byte) :%8d/n" ${BYTE_CODE_SIZE} | tee -a $LOG

printf "Machine Code Size(byte) :%8d/n" ${MACHINE_CODE_SIZE} | tee -a $LOG

printf "Max Machine Code Size(byte):%8d/n" ${MAX_MACHINE_CODE_SIZE} | tee -a $LOG

echo "Memory usage(byte)" | tee -a $LOG

printf "Heap total :%8d/n" ${HEAP_TOTAL} | tee -a $LOG

printf "Heap peak :%8d/n" ${HEAP_PEAK} | tee -a $LOG

printf "Stack peak :%8d/n" ${STACK_PEAK} | tee -a $LOG

echo "*************************************************************" | tee -a $LOG

echo "" | tee -a $LOG

rm case.js

if [ -z ${TIME_JIT} ];then

NG=`expr $NG + 1`

else

OK=`expr $OK + 1`

fi

SUM=`expr $SUM + 1`

done

echo "----------------------------" | tee -a $LOG

printf "TOTAL NUMBER:%3d/n" $SUM | tee -a $LOG

printf "OK NUMBER :%3d/n" $OK | tee -a $LOG

printf "NG NUMBER :%3d/n" $NG | tee -a $LOG

echo "----------------------------" | tee -a $LOG

echo "" | tee -a $LOG

rm tmp -rf
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: