#!/usr/bin/nodejs

const nthCheck = require('../../');
const compile = nthCheck.compile;

const l = 1024;
const inc = 2;
var time_cost = [];
var oldi = 0;
for(var i = 1; i <= l; i=i*inc) {
    var time = Date.now();
    var attack_str = '2n' + ' '.repeat(i*10000)+"!";
    try {
	nthCheck.parse(attack_str) 
    }
    catch(err) {
	time_cost[i] = Date.now() - time;
	console.log("attack_str.length: " + attack_str.length + ": " + time_cost[i]+" ms")
	if(i>1 && time_cost[oldi] > 2 && time_cost[i] > 2)
	    if(time_cost[i] > time_cost[oldi]*(inc+0.5))
		return 1;
    }
    oldi = i;
}
return 0;