mirror of
https://github.com/MrUnknownDE/UnknownBot.git
synced 2026-04-09 17:43:44 +02:00
start nodejs bot
This commit is contained in:
47
node_modules/node-addon-api/benchmark/README.md
generated
vendored
Normal file
47
node_modules/node-addon-api/benchmark/README.md
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
# Benchmarks
|
||||
|
||||
## Running the benchmarks
|
||||
|
||||
From the parent directory, run
|
||||
|
||||
```bash
|
||||
npm run-script benchmark
|
||||
```
|
||||
|
||||
The above script supports the following arguments:
|
||||
|
||||
* `--benchmarks=...`: A semicolon-separated list of benchmark names. These names
|
||||
will be mapped to file names in this directory by appending `.js`.
|
||||
|
||||
## Adding benchmarks
|
||||
|
||||
The steps below should be followed when adding new benchmarks.
|
||||
|
||||
0. Decide on a name for the benchmark. This name will be used in several places.
|
||||
This example will use the name `new_benchmark`.
|
||||
|
||||
0. Create files `new_benchmark.cc` and `new_benchmark.js` in this directory.
|
||||
|
||||
0. Copy an existing benchmark in `binding.gyp` and change the target name prefix
|
||||
and the source file name to `new_benchmark`. This should result in two new
|
||||
targets which look like this:
|
||||
|
||||
```gyp
|
||||
{
|
||||
'target_name': 'new_benchmark',
|
||||
'sources': [ 'new_benchmark.cc' ],
|
||||
'includes': [ '../except.gypi' ],
|
||||
},
|
||||
{
|
||||
'target_name': 'new_benchmark_noexcept',
|
||||
'sources': [ 'new_benchmark.cc' ],
|
||||
'includes': [ '../noexcept.gypi' ],
|
||||
},
|
||||
```
|
||||
|
||||
There should always be a pair of targets: one bearing the name of the
|
||||
benchmark and configured with C++ exceptions enabled, and one bearing the
|
||||
same name followed by the suffix `_noexcept` and configured with C++
|
||||
exceptions disabled. This will ensure that the benchmark can be written to
|
||||
cover both the case where C++ exceptions are enabled and the case where they
|
||||
are disabled.
|
||||
25
node_modules/node-addon-api/benchmark/binding.gyp
generated
vendored
Normal file
25
node_modules/node-addon-api/benchmark/binding.gyp
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
'target_defaults': { 'includes': ['../common.gypi'] },
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'function_args',
|
||||
'sources': [ 'function_args.cc' ],
|
||||
'includes': [ '../except.gypi' ],
|
||||
},
|
||||
{
|
||||
'target_name': 'function_args_noexcept',
|
||||
'sources': [ 'function_args.cc' ],
|
||||
'includes': [ '../noexcept.gypi' ],
|
||||
},
|
||||
{
|
||||
'target_name': 'property_descriptor',
|
||||
'sources': [ 'property_descriptor.cc' ],
|
||||
'includes': [ '../except.gypi' ],
|
||||
},
|
||||
{
|
||||
'target_name': 'property_descriptor_noexcept',
|
||||
'sources': [ 'property_descriptor.cc' ],
|
||||
'includes': [ '../noexcept.gypi' ],
|
||||
},
|
||||
]
|
||||
}
|
||||
217
node_modules/node-addon-api/benchmark/function_args.cc
generated
vendored
Normal file
217
node_modules/node-addon-api/benchmark/function_args.cc
generated
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
#include "napi.h"
|
||||
|
||||
static napi_value NoArgFunction_Core(napi_env env, napi_callback_info info) {
|
||||
(void) env;
|
||||
(void) info;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value OneArgFunction_Core(napi_env env, napi_callback_info info) {
|
||||
size_t argc = 1;
|
||||
napi_value argv;
|
||||
if (napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
(void) argv;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value TwoArgFunction_Core(napi_env env, napi_callback_info info) {
|
||||
size_t argc = 2;
|
||||
napi_value argv[2];
|
||||
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
(void) argv[0];
|
||||
(void) argv[1];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value ThreeArgFunction_Core(napi_env env, napi_callback_info info) {
|
||||
size_t argc = 3;
|
||||
napi_value argv[3];
|
||||
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
(void) argv[0];
|
||||
(void) argv[1];
|
||||
(void) argv[2];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value FourArgFunction_Core(napi_env env, napi_callback_info info) {
|
||||
size_t argc = 4;
|
||||
napi_value argv[4];
|
||||
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
(void) argv[0];
|
||||
(void) argv[1];
|
||||
(void) argv[2];
|
||||
(void) argv[3];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void NoArgFunction(const Napi::CallbackInfo& info) {
|
||||
(void) info;
|
||||
}
|
||||
|
||||
static void OneArgFunction(const Napi::CallbackInfo& info) {
|
||||
Napi::Value argv0 = info[0]; (void) argv0;
|
||||
}
|
||||
|
||||
static void TwoArgFunction(const Napi::CallbackInfo& info) {
|
||||
Napi::Value argv0 = info[0]; (void) argv0;
|
||||
Napi::Value argv1 = info[1]; (void) argv1;
|
||||
}
|
||||
|
||||
static void ThreeArgFunction(const Napi::CallbackInfo& info) {
|
||||
Napi::Value argv0 = info[0]; (void) argv0;
|
||||
Napi::Value argv1 = info[1]; (void) argv1;
|
||||
Napi::Value argv2 = info[2]; (void) argv2;
|
||||
}
|
||||
|
||||
static void FourArgFunction(const Napi::CallbackInfo& info) {
|
||||
Napi::Value argv0 = info[0]; (void) argv0;
|
||||
Napi::Value argv1 = info[1]; (void) argv1;
|
||||
Napi::Value argv2 = info[2]; (void) argv2;
|
||||
Napi::Value argv3 = info[3]; (void) argv3;
|
||||
}
|
||||
|
||||
#if NAPI_VERSION > 5
|
||||
class FunctionArgsBenchmark : public Napi::Addon<FunctionArgsBenchmark> {
|
||||
public:
|
||||
FunctionArgsBenchmark(Napi::Env env, Napi::Object exports) {
|
||||
DefineAddon(exports, {
|
||||
InstanceValue("addon", DefineProperties(Napi::Object::New(env), {
|
||||
InstanceMethod("noArgFunction", &FunctionArgsBenchmark::NoArgFunction),
|
||||
InstanceMethod("oneArgFunction",
|
||||
&FunctionArgsBenchmark::OneArgFunction),
|
||||
InstanceMethod("twoArgFunction",
|
||||
&FunctionArgsBenchmark::TwoArgFunction),
|
||||
InstanceMethod("threeArgFunction",
|
||||
&FunctionArgsBenchmark::ThreeArgFunction),
|
||||
InstanceMethod("fourArgFunction",
|
||||
&FunctionArgsBenchmark::FourArgFunction),
|
||||
}), napi_enumerable),
|
||||
InstanceValue("addon_templated",
|
||||
DefineProperties(Napi::Object::New(env), {
|
||||
InstanceMethod<&FunctionArgsBenchmark::NoArgFunction>(
|
||||
"noArgFunction"),
|
||||
InstanceMethod<&FunctionArgsBenchmark::OneArgFunction>(
|
||||
"oneArgFunction"),
|
||||
InstanceMethod<&FunctionArgsBenchmark::TwoArgFunction>(
|
||||
"twoArgFunction"),
|
||||
InstanceMethod<&FunctionArgsBenchmark::ThreeArgFunction>(
|
||||
"threeArgFunction"),
|
||||
InstanceMethod<&FunctionArgsBenchmark::FourArgFunction>(
|
||||
"fourArgFunction"),
|
||||
}), napi_enumerable),
|
||||
});
|
||||
}
|
||||
private:
|
||||
void NoArgFunction(const Napi::CallbackInfo& info) {
|
||||
(void) info;
|
||||
}
|
||||
|
||||
void OneArgFunction(const Napi::CallbackInfo& info) {
|
||||
Napi::Value argv0 = info[0]; (void) argv0;
|
||||
}
|
||||
|
||||
void TwoArgFunction(const Napi::CallbackInfo& info) {
|
||||
Napi::Value argv0 = info[0]; (void) argv0;
|
||||
Napi::Value argv1 = info[1]; (void) argv1;
|
||||
}
|
||||
|
||||
void ThreeArgFunction(const Napi::CallbackInfo& info) {
|
||||
Napi::Value argv0 = info[0]; (void) argv0;
|
||||
Napi::Value argv1 = info[1]; (void) argv1;
|
||||
Napi::Value argv2 = info[2]; (void) argv2;
|
||||
}
|
||||
|
||||
void FourArgFunction(const Napi::CallbackInfo& info) {
|
||||
Napi::Value argv0 = info[0]; (void) argv0;
|
||||
Napi::Value argv1 = info[1]; (void) argv1;
|
||||
Napi::Value argv2 = info[2]; (void) argv2;
|
||||
Napi::Value argv3 = info[3]; (void) argv3;
|
||||
}
|
||||
};
|
||||
#endif // NAPI_VERSION > 5
|
||||
|
||||
static Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
||||
napi_value no_arg_function, one_arg_function, two_arg_function,
|
||||
three_arg_function, four_arg_function;
|
||||
napi_status status;
|
||||
|
||||
status = napi_create_function(env,
|
||||
"noArgFunction",
|
||||
NAPI_AUTO_LENGTH,
|
||||
NoArgFunction_Core,
|
||||
nullptr,
|
||||
&no_arg_function);
|
||||
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
||||
|
||||
status = napi_create_function(env,
|
||||
"oneArgFunction",
|
||||
NAPI_AUTO_LENGTH,
|
||||
OneArgFunction_Core,
|
||||
nullptr,
|
||||
&one_arg_function);
|
||||
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
||||
|
||||
status = napi_create_function(env,
|
||||
"twoArgFunction",
|
||||
NAPI_AUTO_LENGTH,
|
||||
TwoArgFunction_Core,
|
||||
nullptr,
|
||||
&two_arg_function);
|
||||
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
||||
|
||||
status = napi_create_function(env,
|
||||
"threeArgFunction",
|
||||
NAPI_AUTO_LENGTH,
|
||||
ThreeArgFunction_Core,
|
||||
nullptr,
|
||||
&three_arg_function);
|
||||
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
||||
|
||||
status = napi_create_function(env,
|
||||
"fourArgFunction",
|
||||
NAPI_AUTO_LENGTH,
|
||||
FourArgFunction_Core,
|
||||
nullptr,
|
||||
&four_arg_function);
|
||||
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
||||
|
||||
Napi::Object core = Napi::Object::New(env);
|
||||
core["noArgFunction"] = Napi::Value(env, no_arg_function);
|
||||
core["oneArgFunction"] = Napi::Value(env, one_arg_function);
|
||||
core["twoArgFunction"] = Napi::Value(env, two_arg_function);
|
||||
core["threeArgFunction"] = Napi::Value(env, three_arg_function);
|
||||
core["fourArgFunction"] = Napi::Value(env, four_arg_function);
|
||||
exports["core"] = core;
|
||||
|
||||
Napi::Object cplusplus = Napi::Object::New(env);
|
||||
cplusplus["noArgFunction"] = Napi::Function::New(env, NoArgFunction);
|
||||
cplusplus["oneArgFunction"] = Napi::Function::New(env, OneArgFunction);
|
||||
cplusplus["twoArgFunction"] = Napi::Function::New(env, TwoArgFunction);
|
||||
cplusplus["threeArgFunction"] = Napi::Function::New(env, ThreeArgFunction);
|
||||
cplusplus["fourArgFunction"] = Napi::Function::New(env, FourArgFunction);
|
||||
exports["cplusplus"] = cplusplus;
|
||||
|
||||
Napi::Object templated = Napi::Object::New(env);
|
||||
templated["noArgFunction"] = Napi::Function::New<NoArgFunction>(env);
|
||||
templated["oneArgFunction"] = Napi::Function::New<OneArgFunction>(env);
|
||||
templated["twoArgFunction"] = Napi::Function::New<TwoArgFunction>(env);
|
||||
templated["threeArgFunction"] = Napi::Function::New<ThreeArgFunction>(env);
|
||||
templated["fourArgFunction"] = Napi::Function::New<FourArgFunction>(env);
|
||||
exports["templated"] = templated;
|
||||
|
||||
#if NAPI_VERSION > 5
|
||||
FunctionArgsBenchmark::Init(env, exports);
|
||||
#endif // NAPI_VERSION > 5
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
|
||||
60
node_modules/node-addon-api/benchmark/function_args.js
generated
vendored
Normal file
60
node_modules/node-addon-api/benchmark/function_args.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
const path = require('path');
|
||||
const Benchmark = require('benchmark');
|
||||
const addonName = path.basename(__filename, '.js');
|
||||
|
||||
[ addonName, addonName + '_noexcept' ]
|
||||
.forEach((addonName) => {
|
||||
const rootAddon = require('bindings')({
|
||||
bindings: addonName,
|
||||
module_root: __dirname
|
||||
});
|
||||
delete rootAddon.path;
|
||||
const implems = Object.keys(rootAddon);
|
||||
const maxNameLength =
|
||||
implems.reduce((soFar, value) => Math.max(soFar, value.length), 0);
|
||||
const anObject = {};
|
||||
|
||||
console.log(`\n${addonName}: `);
|
||||
|
||||
console.log('no arguments:');
|
||||
implems.reduce((suite, implem) => {
|
||||
const fn = rootAddon[implem].noArgFunction;
|
||||
return suite.add(implem.padStart(maxNameLength, ' '), () => fn());
|
||||
}, new Benchmark.Suite)
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run();
|
||||
|
||||
console.log('one argument:');
|
||||
implems.reduce((suite, implem) => {
|
||||
const fn = rootAddon[implem].oneArgFunction;
|
||||
return suite.add(implem.padStart(maxNameLength, ' '), () => fn('x'));
|
||||
}, new Benchmark.Suite)
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run();
|
||||
|
||||
console.log('two arguments:');
|
||||
implems.reduce((suite, implem) => {
|
||||
const fn = rootAddon[implem].twoArgFunction;
|
||||
return suite.add(implem.padStart(maxNameLength, ' '), () => fn('x', 12));
|
||||
}, new Benchmark.Suite)
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run();
|
||||
|
||||
console.log('three arguments:');
|
||||
implems.reduce((suite, implem) => {
|
||||
const fn = rootAddon[implem].threeArgFunction;
|
||||
return suite.add(implem.padStart(maxNameLength, ' '),
|
||||
() => fn('x', 12, true));
|
||||
}, new Benchmark.Suite)
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run();
|
||||
|
||||
console.log('four arguments:');
|
||||
implems.reduce((suite, implem) => {
|
||||
const fn = rootAddon[implem].fourArgFunction;
|
||||
return suite.add(implem.padStart(maxNameLength, ' '),
|
||||
() => fn('x', 12, true, anObject));
|
||||
}, new Benchmark.Suite)
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run();
|
||||
});
|
||||
34
node_modules/node-addon-api/benchmark/index.js
generated
vendored
Normal file
34
node_modules/node-addon-api/benchmark/index.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const { readdirSync } = require('fs');
|
||||
const { spawnSync } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
let benchmarks = [];
|
||||
|
||||
if (!!process.env.npm_config_benchmarks) {
|
||||
benchmarks = process.env.npm_config_benchmarks
|
||||
.split(';')
|
||||
.map((item) => (item + '.js'));
|
||||
}
|
||||
|
||||
// Run each file in this directory or the list given on the command line except
|
||||
// index.js as a Node.js process.
|
||||
(benchmarks.length > 0 ? benchmarks : readdirSync(__dirname))
|
||||
.filter((item) => (item !== 'index.js' && item.match(/\.js$/)))
|
||||
.map((item) => path.join(__dirname, item))
|
||||
.forEach((item) => {
|
||||
const child = spawnSync(process.execPath, [
|
||||
'--expose-gc',
|
||||
item
|
||||
], { stdio: 'inherit' });
|
||||
if (child.signal) {
|
||||
console.error(`Tests aborted with ${child.signal}`);
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
process.exitCode = child.status;
|
||||
}
|
||||
if (child.status !== 0) {
|
||||
process.exit(process.exitCode);
|
||||
}
|
||||
});
|
||||
91
node_modules/node-addon-api/benchmark/property_descriptor.cc
generated
vendored
Normal file
91
node_modules/node-addon-api/benchmark/property_descriptor.cc
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "napi.h"
|
||||
|
||||
static napi_value Getter_Core(napi_env env, napi_callback_info info) {
|
||||
(void) info;
|
||||
napi_value result;
|
||||
napi_status status = napi_create_uint32(env, 42, &result);
|
||||
NAPI_THROW_IF_FAILED(env, status, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
static napi_value Setter_Core(napi_env env, napi_callback_info info) {
|
||||
size_t argc = 1;
|
||||
napi_value argv;
|
||||
napi_status status =
|
||||
napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr);
|
||||
NAPI_THROW_IF_FAILED(env, status, nullptr);
|
||||
(void) argv;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static Napi::Value Getter(const Napi::CallbackInfo& info) {
|
||||
return Napi::Number::New(info.Env(), 42);
|
||||
}
|
||||
|
||||
static void Setter(const Napi::CallbackInfo& info) {
|
||||
(void) info[0];
|
||||
}
|
||||
|
||||
#if NAPI_VERSION > 5
|
||||
class PropDescBenchmark : public Napi::Addon<PropDescBenchmark> {
|
||||
public:
|
||||
PropDescBenchmark(Napi::Env, Napi::Object exports) {
|
||||
DefineAddon(exports, {
|
||||
InstanceAccessor("addon",
|
||||
&PropDescBenchmark::Getter,
|
||||
&PropDescBenchmark::Setter,
|
||||
napi_enumerable),
|
||||
InstanceAccessor<&PropDescBenchmark::Getter,
|
||||
&PropDescBenchmark::Setter>("addon_templated",
|
||||
napi_enumerable),
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
Napi::Value Getter(const Napi::CallbackInfo& info) {
|
||||
return Napi::Number::New(info.Env(), 42);
|
||||
}
|
||||
|
||||
void Setter(const Napi::CallbackInfo& info, const Napi::Value& val) {
|
||||
(void) info[0];
|
||||
(void) val;
|
||||
}
|
||||
};
|
||||
#endif // NAPI_VERSION > 5
|
||||
|
||||
static Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
||||
napi_status status;
|
||||
napi_property_descriptor core_prop = {
|
||||
"core",
|
||||
nullptr,
|
||||
nullptr,
|
||||
Getter_Core,
|
||||
Setter_Core,
|
||||
nullptr,
|
||||
napi_enumerable,
|
||||
nullptr
|
||||
};
|
||||
|
||||
status = napi_define_properties(env, exports, 1, &core_prop);
|
||||
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
||||
|
||||
exports.DefineProperty(
|
||||
Napi::PropertyDescriptor::Accessor(env,
|
||||
exports,
|
||||
"cplusplus",
|
||||
Getter,
|
||||
Setter,
|
||||
napi_enumerable));
|
||||
|
||||
exports.DefineProperty(
|
||||
Napi::PropertyDescriptor::Accessor<Getter, Setter>("templated",
|
||||
napi_enumerable));
|
||||
|
||||
#if NAPI_VERSION > 5
|
||||
PropDescBenchmark::Init(env, exports);
|
||||
#endif // NAPI_VERSION > 5
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
|
||||
37
node_modules/node-addon-api/benchmark/property_descriptor.js
generated
vendored
Normal file
37
node_modules/node-addon-api/benchmark/property_descriptor.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
const path = require('path');
|
||||
const Benchmark = require('benchmark');
|
||||
const addonName = path.basename(__filename, '.js');
|
||||
|
||||
[ addonName, addonName + '_noexcept' ]
|
||||
.forEach((addonName) => {
|
||||
const rootAddon = require('bindings')({
|
||||
bindings: addonName,
|
||||
module_root: __dirname
|
||||
});
|
||||
delete rootAddon.path;
|
||||
const getters = new Benchmark.Suite;
|
||||
const setters = new Benchmark.Suite;
|
||||
const maxNameLength = Object.keys(rootAddon)
|
||||
.reduce((soFar, value) => Math.max(soFar, value.length), 0);
|
||||
|
||||
console.log(`\n${addonName}: `);
|
||||
|
||||
Object.keys(rootAddon).forEach((key) => {
|
||||
getters.add(`${key} getter`.padStart(maxNameLength + 7), () => {
|
||||
const x = rootAddon[key];
|
||||
});
|
||||
setters.add(`${key} setter`.padStart(maxNameLength + 7), () => {
|
||||
rootAddon[key] = 5;
|
||||
})
|
||||
});
|
||||
|
||||
getters
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run();
|
||||
|
||||
console.log('');
|
||||
|
||||
setters
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run();
|
||||
});
|
||||
Reference in New Issue
Block a user