<commit_before>module('legind.instrumentation').requires('lively.ast.Rewriting').toRun(function() {

Object.subclass('legind.instrumentation.CModel',
'initializing', {
    initialize: function(argIdx) {
        this.argIdx = argIdx;
        this.n = 0;
        this.meanX = 0;
        this.meanY = 0;
        this.varX = 0;
        this.covarXY = 0;
        this.loss = 0;
    }
},
'analysis', {
    fit: function(args, time) {
        var x = this.kernel(args[this.argIdx]);
        var y = time;
        if (this.varX > 0) {
            var beta = this.covarXY / this.varX;
            var pred = 0|(this.meanY - beta* this.meanX + beta* x);
            this.loss = (0|(.99 * this.loss)) + (y - pred) * (y - pred);
        }
        this.n++;
        var meanX1 = this.meanX + (x - this.meanX) / this.n;
        var meanY1 = this.meanY + (y - this.meanY) / this.n;
        this.varX = this.varX + (x - this.meanX) * (x - meanX1);
        this.covarXY = this.covarXY + (x - this.meanX) * (y - meanY1);
        this.meanX = meanX1;
        this.meanY = meanY1;
    },
    alpha: function() {
        return this.meanY - this.meanX * this.beta();
    },
    beta: function() {
        return this.covarXY / this.varX;
    },
    _predict: function(arg) {
        return this.alpha() + this.beta() * this.kernel(arg);
    },
    predict: function(args) {
        return this._predict(args[this.argIdx]);
    }
},
'interface', {
    describe: function() {
        var log = Math.log(1 + this.loss / this.meanY);
        return this.name() + ":  " + (0|log) + "\n";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CLinear',
'analysis', {
    kernel: function(x) {
        return x;
    }
}, 'interface', {
    name: function() {
        return "O(n)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CQuadratic',
'analysis', {
    kernel: function(x) {
        return x * x;
    }
}, 'interface', {
    name: function() {
        return "O(n²)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CCubic',
'analysis', {
    kernel: function(x) {
        return x * x * x;
    }
}, 'interface', {
    name: function() {
        return "O(n³)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CLogarithmic',
'analysis', {
    kernel: function(x) {
        return Math.log(x);
    }
}, 'interface', {
    name: function() {
        return "O(log n)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CHyperLogarithmic',
'analysis', {
    kernel: function(x) {
        return x * Math.log(x);
    }
}, 'interface', {
    name: function() {
        return "O(x log x)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CExponential',
'analysis', {
    kernel: function(x) {
        return Math.pow(2,x);
    }
}, 'interface', {
    name: function() {
        return "O(2ⁿ)";
    }
});

Object.subclass('legind.instrumentation.Profiler',
'initializing', {
    initialize: function() {
        this.timers = [];
    }
},
'profiling', {
    startTimer: function(id, args) {
        this.timers.push([Date.now(), id, args]);
    },
    stopTimer: function() {
        var last = this.timers.pop();
        var time = Date.now() - last[0];
        if (time > 0) {
            this.record(last[1], time, last[2]);
        }
    },
    record: function(id, time, args) {
        var report = this.report[id];
        report.total += time;
        var nmodels = report.cmodels.length;
        for (var i = 0; i < nmodels; i++) {
            report.cmodels[i].fit(args, time);
        }
        if (report.inv.length <= 120) {
            report.inv.push({args: args, time: time});
        }
    },
},
'reporting', {
    getReport: function() {
        return this.report;
    }
},
'running', {
    profile: function(cb) {
        legind.instrumentation.Profiler.current = this;
        cb();
        return this.getReport();
    },<commit_msg>support for strings and arrays as input size<commit_after>module('legind.instrumentation').requires('lively.ast.Rewriting').toRun(function() {

Object.subclass('legind.instrumentation.CModel',
'initializing', {
    initialize: function(argIdx) {
        this.argIdx = argIdx;
        this.n = 0;
        this.meanX = 0;
        this.meanY = 0;
        this.varX = 0;
        this.covarXY = 0;
        this.loss = 0;
    }
},
'analysis', {
    fit: function(args, time) {
        var x = this.kernel(args[this.argIdx]);
        var y = time;
        if (this.varX > 0) {
            var beta = this.covarXY / this.varX;
            var pred = 0|(this.meanY - beta* this.meanX + beta* x);
            this.loss = (0|(.99 * this.loss)) + (y - pred) * (y - pred);
        }
        this.n++;
        var meanX1 = this.meanX + (x - this.meanX) / this.n;
        var meanY1 = this.meanY + (y - this.meanY) / this.n;
        this.varX = this.varX + (x - this.meanX) * (x - meanX1);
        this.covarXY = this.covarXY + (x - this.meanX) * (y - meanY1);
        this.meanX = meanX1;
        this.meanY = meanY1;
    },
    alpha: function() {
        return this.meanY - this.meanX * this.beta();
    },
    beta: function() {
        return this.covarXY / this.varX;
    },
    _predict: function(arg) {
        return this.alpha() + this.beta() * this.kernel(arg);
    },
    predict: function(args) {
        return this._predict(args[this.argIdx]);
    }
},
'interface', {
    describe: function() {
        var log = Math.log(1 + this.loss / this.meanY);
        return this.name() + ":  " + (0|log) + "\n";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CLinear',
'analysis', {
    kernel: function(x) {
        return x;
    }
}, 'interface', {
    name: function() {
        return "O(n)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CQuadratic',
'analysis', {
    kernel: function(x) {
        return x * x;
    }
}, 'interface', {
    name: function() {
        return "O(n²)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CCubic',
'analysis', {
    kernel: function(x) {
        return x * x * x;
    }
}, 'interface', {
    name: function() {
        return "O(n³)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CLogarithmic',
'analysis', {
    kernel: function(x) {
        return Math.log(x);
    }
}, 'interface', {
    name: function() {
        return "O(log n)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CHyperLogarithmic',
'analysis', {
    kernel: function(x) {
        return x * Math.log(x);
    }
}, 'interface', {
    name: function() {
        return "O(x log x)";
    }
});

legind.instrumentation.CModel.subclass('legind.instrumentation.CExponential',
'analysis', {
    kernel: function(x) {
        return Math.pow(2,x);
    }
}, 'interface', {
    name: function() {
        return "O(2ⁿ)";
    }
});

Object.subclass('legind.instrumentation.Profiler',
'initializing', {
    initialize: function() {
        this.timers = [];
    }
},
'profiling', {
    startTimer: function(id, args) {
        var nargs = args.length;
        var fargs = new Array(nargs);
        for (var i = 0; i < nargs; i++) {
            var a =  args[i];
            var t = typeof a;
            if (t === "number") {
                fargs[i] = a;
            } else if (t === "string") {
                fargs[i] = a.length;
            } else if (args instanceof Array) {
                fargs[i] = a.length;
            } else {
                fargs[i] = 1;
            }
        }
        this.timers.push([Date.now(), id, fargs]);
    },
    stopTimer: function() {
        var last = this.timers.pop();
        var time = Date.now() - last[0];
        if (time > 0) {
            this.record(last[1], time, last[2]);
        }
    },
    record: function(id, time, args) {
        var report = this.report[id];
        report.total += time;
        var nmodels = report.cmodels.length;
        for (var i = 0; i < nmodels; i++) {
            report.cmodels[i].fit(args, time);
        }
        if (report.inv.length <= 120) {
            report.inv.push({args: args, time: time});
        }
    },
},
'reporting', {
    getReport: function() {
        return this.report;
    }
},
'running', {
    profile: function(cb) {
        legind.instrumentation.Profiler.current = this;
        cb();
        return this.getReport();
    },
{'fraction_non_alphanumeric': 0.1700744592837726, 'fraction_numerical': 0.007091360359295591, 'mean_word_length': 2.06150506512301, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 7, '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': '1024183', 'n_tokens_mistral': 2964, 'n_tokens_neox': 2921, 'n_words': 555}