(test-it.sh)

來源:互聯網
上載者:User

#!/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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.