JSPerf中ops / second与百分比之间的关系是什么?

时间:2017-05-13 00:08:20

标签: javascript jsperf

JSPerf test results

" X%如何放慢"数字计算?我想也许是:

(fastest - slower) / fastest

但在这种情况下,那是:

(672555 - 194412) / 672555 = 0.7109351651537792

也许使用了误差幅度?

1 个答案:

答案 0 :(得分:0)

请参阅https://github.com/bestiejs/benchmark.js/blob/7fc4c3cf7c4bccff4dbce58883a4181c2e830f85/example/jsperf/ui.js#L556

#include <stdio.h>

#define DATA_MAX_LEN 100

int main(void){
    int n[DATA_MAX_LEN], i, len, loop_end;
    char x[DATA_MAX_LEN], newline[2], ch;

    while(scanf("%1[\n]", newline) != 1){//End with empty line(only newline), Need EOF check
        for(loop_end = len = i = 0; i < DATA_MAX_LEN && !loop_end; ++i){
            //format: integer character[space|newline]
            if(scanf("%d %c%c", &n[i], &x[i], &ch) != 3)
                loop_end = printf("invalid format.\n");
            else if(ch == '\n')
                loop_end = len = ++i;
            else if(ch != ' ')
                loop_end = printf("invalid format.\n");
        }
        for(i = 0; i < len; ++i){
            printf("%d %c ", n[i], x[i]);
        }
        printf("\n");
    }
}