mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add benches
This commit is contained in:
1 parent
319bb807fb
commit
7822f6d8d8
6 files changed
+2142
-4
No files matched your search
Generated
+22
@@ -185,6 +185,16 @@ name = "constant_time_eq"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cpython"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"python3-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.11"
|
||||
@@ -551,6 +561,15 @@ dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python3-sys"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.2"
|
||||
@@ -771,6 +790,7 @@ name = "rustpython"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cpython 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustpython_parser 0.0.1",
|
||||
@@ -1328,6 +1348,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
|
||||
"checksum cpython 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b489034e723e7f5109fecd19b719e664f89ef925be785885252469e9822fa940"
|
||||
"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
|
||||
"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c"
|
||||
"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
|
||||
@@ -1374,6 +1395,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0"
|
||||
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||
"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915"
|
||||
"checksum python3-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "61e4aac43f833fd637e429506cb2ac9d7df672c4b68f2eaaa163649b7fdc0444"
|
||||
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
|
||||
"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
|
||||
"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9"
|
||||
|
||||
@@ -7,6 +7,11 @@ edition = "2018"
|
||||
[workspace]
|
||||
members = [".", "derive", "vm", "wasm/lib", "parser"]
|
||||
|
||||
[[bench]]
|
||||
name = "bench"
|
||||
path = "./benchmarks/bench.rs"
|
||||
|
||||
|
||||
[dependencies]
|
||||
log="0.4.1"
|
||||
env_logger="0.5.10"
|
||||
@@ -15,3 +20,6 @@ rustpython_parser = {path = "parser"}
|
||||
rustpython_vm = {path = "vm"}
|
||||
rustyline = "2.1.0"
|
||||
xdg = "2.2.0"
|
||||
|
||||
[dev-dependencies.cpython]
|
||||
version = "0.2"
|
||||
@@ -0,0 +1,125 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate cpython;
|
||||
extern crate rustpython_parser;
|
||||
extern crate rustpython_vm;
|
||||
extern crate test;
|
||||
|
||||
use rustpython_vm::pyobject::PyResult;
|
||||
use rustpython_vm::{compile, VirtualMachine};
|
||||
|
||||
#[bench]
|
||||
fn bench_tokenization(b: &mut test::Bencher) {
|
||||
use rustpython_parser::lexer::{make_tokenizer, Tok};
|
||||
|
||||
let source = include_str!("./benchmarks/minidom.py");
|
||||
|
||||
b.bytes = source.len() as _;
|
||||
b.iter(|| {
|
||||
let lexer = make_tokenizer(source);
|
||||
for res in lexer {
|
||||
let _token: Tok = res.unwrap().1;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rustpy_parse_to_ast(b: &mut test::Bencher) {
|
||||
use rustpython_parser::parser::parse_program;
|
||||
|
||||
let source = include_str!("./benchmarks/minidom.py");
|
||||
|
||||
b.bytes = source.len() as _;
|
||||
b.iter(|| parse_program(source).unwrap())
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cpython_parse_to_ast(b: &mut test::Bencher) {
|
||||
let source = include_str!("./benchmarks/minidom.py");
|
||||
|
||||
let gil = cpython::Python::acquire_gil();
|
||||
let python = gil.python();
|
||||
|
||||
let globals = None;
|
||||
let locals = cpython::PyDict::new(python);
|
||||
|
||||
locals.set_item(python, "SOURCE_CODE", source).unwrap();
|
||||
|
||||
let code = "compile(SOURCE_CODE, mode=\"exec\", filename=\"minidom.py\")";
|
||||
|
||||
b.bytes = source.len() as _;
|
||||
b.iter(|| {
|
||||
let res: cpython::PyResult<cpython::PyObject> = python.eval(code, globals, Some(&locals));
|
||||
assert!(res.is_ok());
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cpython_nbody(b: &mut test::Bencher) {
|
||||
let source = include_str!("./benchmarks/nbody.py");
|
||||
|
||||
let gil = cpython::Python::acquire_gil();
|
||||
let python = gil.python();
|
||||
|
||||
let globals = None;
|
||||
let locals = None;
|
||||
|
||||
b.iter(|| {
|
||||
let res: cpython::PyResult<()> = python.run(source, globals, locals);
|
||||
assert!(res.is_ok());
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cpython_mandelbrot(b: &mut test::Bencher) {
|
||||
let source = include_str!("./benchmarks/mandelbrot.py");
|
||||
|
||||
let gil = cpython::Python::acquire_gil();
|
||||
let python = gil.python();
|
||||
|
||||
let globals = None;
|
||||
let locals = None;
|
||||
|
||||
b.iter(|| {
|
||||
let res: cpython::PyResult<()> = python.run(source, globals, locals);
|
||||
assert!(res.is_ok());
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rustpy_nbody(b: &mut test::Bencher) {
|
||||
// NOTE: Take long time.
|
||||
let source = include_str!("./benchmarks/nbody.py");
|
||||
|
||||
let vm = VirtualMachine::new();
|
||||
|
||||
let code = match compile::compile(&vm, source, &compile::Mode::Single, "<stdin>".to_string()) {
|
||||
Ok(code) => code,
|
||||
Err(e) => panic!("{:?}", e),
|
||||
};
|
||||
|
||||
b.iter(|| {
|
||||
let scope = vm.ctx.new_scope();
|
||||
let res: PyResult = vm.run_code_obj(code.clone(), scope);
|
||||
assert!(res.is_ok());
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rustpy_mandelbrot(b: &mut test::Bencher) {
|
||||
// NOTE: Take long time.
|
||||
let source = include_str!("./benchmarks/mandelbrot.py");
|
||||
|
||||
let vm = VirtualMachine::new();
|
||||
|
||||
let code = match compile::compile(&vm, source, &compile::Mode::Single, "<stdin>".to_string()) {
|
||||
Ok(code) => code,
|
||||
Err(e) => panic!("{:?}", e),
|
||||
};
|
||||
|
||||
b.iter(|| {
|
||||
let scope = vm.ctx.new_scope();
|
||||
let res: PyResult = vm.run_code_obj(code.clone(), scope);
|
||||
assert!(res.is_ok());
|
||||
})
|
||||
}
|
||||
@@ -21,11 +21,13 @@ while y < h:
|
||||
i = i+1
|
||||
|
||||
if Tr+Ti <= 4:
|
||||
print('*', end='')
|
||||
# print('*', end='')
|
||||
pass
|
||||
else:
|
||||
print('·', end='')
|
||||
# print('·', end='')
|
||||
pass
|
||||
|
||||
x = x+1
|
||||
|
||||
print()
|
||||
# print()
|
||||
y = y+1
|
||||
File diff suppressed because it is too large.
Load diff
@@ -89,7 +89,7 @@ def report_energy(bodies=SYSTEM, pairs=PAIRS, e=0.0):
|
||||
e -= (m1 * m2) / ((dx * dx + dy * dy + dz * dz) ** 0.5)
|
||||
for (r, [vx, vy, vz], m) in bodies:
|
||||
e += m * (vx * vx + vy * vy + vz * vz) / 2.
|
||||
print(f"{e}")
|
||||
# print(f"{e}")
|
||||
|
||||
def offset_momentum(ref, bodies=SYSTEM, px=0.0, py=0.0, pz=0.0):
|
||||
for (r, [vx, vy, vz], m) in bodies:
|
||||
|
||||
Reference in new issue
Block a user