<commit_before>#!/bin/bash

src=$1
dist=${src/GPUTEST/GPUTEST_OUT}

echo "Converting $src -> $dist"

dir=${dist%/*}
if [ ! -d "$dir" ]; then
    mkdir -p $dir
fi

suc=-1

# arg1=start, arg2=end, format: %s.%N  
function calcTimeCost() {  
    start=$1  
    end=$2  
     
    start_s=$(echo $start | cut -d '.' -f 1)  
    start_ns=$(echo $start | cut -d '.' -f 2)  
    end_s=$(echo $end | cut -d '.' -f 1)  
    end_ns=$(echo $end | cut -d '.' -f 2)  
  
  
    time=$(( ( 10#$end_s - 10#$start_s ) * 1000 + ( 10#$end_ns / 1000000 - 10#$start_ns / 1000000 ) ))  
    
    s1=`stat -c %s $src | tr -d '\n'`
    s2=`stat -c %s $dist | tr -d '\n'`

    val=`./calc_ssim_psnr -i $src -o $dist`
    arr=(${val//,/ })

    rate=$(awk -v before=$s1 -v after=$s2 'BEGIN{print after/before }')
    ssim=${arr[1]}
    psnr=${arr[2]}
     
    echo "$src,$dist,$time,$suc,$s1,$s2,$rate,$ssim,$psnr" >> guetzli.cuda.csv

    #copy failed picture
    if [ $suc == 1 ]; then
        cp $src ./fail_pics/
        return
    fi

    #copy low quality picture
    if [ $(echo "$ssim < 0.85"|bc) == 1 ] || [ $(echo "$psnr < 30.0"|bc) == 1 ]; then
        cp $src ./low_quality/
    fi

    #copy picture if it become larger
    if [ $(echo "$rate > 1.0"|bc) == 1 ]; then
        cp $src ./become_larger/
    fi
}

start=$(date +%s.%N)
./guetzli --cuda $src $dist
suc=$?
end=$(date +%s.%N)
calcTimeCost $start $end<commit_msg>质量85跑一次测试<commit_after>#!/bin/bash

src=$1
dist=${src/GPUTEST/GPUTEST_OUT}

echo "Converting $src -> $dist"

dir=${dist%/*}
if [ ! -d "$dir" ]; then
    mkdir -p $dir
fi

suc=-1

# arg1=start, arg2=end, format: %s.%N  
function calcTimeCost() {  
    start=$1  
    end=$2  
     
    start_s=$(echo $start | cut -d '.' -f 1)  
    start_ns=$(echo $start | cut -d '.' -f 2)  
    end_s=$(echo $end | cut -d '.' -f 1)  
    end_ns=$(echo $end | cut -d '.' -f 2)  
  
  
    time=$(( ( 10#$end_s - 10#$start_s ) * 1000 + ( 10#$end_ns / 1000000 - 10#$start_ns / 1000000 ) ))  
    
    s1=`stat -c %s $src | tr -d '\n'`
    s2=`stat -c %s $dist | tr -d '\n'`

    val=`./calc_ssim_psnr -i $src -o $dist`
    arr=(${val//,/ })

    rate=$(awk -v before=$s1 -v after=$s2 'BEGIN{print after/before }')
    ssim=${arr[1]}
    psnr=${arr[2]}
     
    echo "$src,$dist,$time,$suc,$s1,$s2,$rate,$ssim,$psnr" >> guetzli.cuda.csv

    #copy failed picture
    if [ $suc == 1 ]; then
        cp $src ./fail_pics/
        return
    fi

    #copy low quality picture
    if [ $(echo "$ssim < 0.85"|bc) == 1 ] || [ $(echo "$psnr < 30.0"|bc) == 1 ]; then
        cp $src ./low_quality/
    fi

    #copy picture if it become larger
    if [ $(echo "$rate > 1.0"|bc) == 1 ]; then
        cp $src ./become_larger/
    fi
}

start=$(date +%s.%N)
./guetzli --quality 85 --cuda $src $dist
suc=$?
end=$(date +%s.%N)
calcTimeCost $start $end
{'fraction_non_alphanumeric': 0.2177447861435136, 'fraction_numerical': 0.041003888299752565, 'mean_word_length': 2.204983012457531, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5203323', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1180, 'n_words': 295}