mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Update cpython dev-dependency and clean up bench.rs
This commit is contained in:
3 files changed
+33
-52
No files matched your search
Generated
+5
-4
@@ -279,12 +279,13 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
||||
|
||||
[[package]]
|
||||
name = "cpython"
|
||||
version = "0.2.1"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b489034e723e7f5109fecd19b719e664f89ef925be785885252469e9822fa940"
|
||||
checksum = "c2efcf01fcd3a7322d82970f45bc02cc089282fe9dea6f6efb45b173f10eacec"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"num-traits",
|
||||
"paste",
|
||||
"python3-sys",
|
||||
]
|
||||
|
||||
@@ -1121,9 +1122,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "python3-sys"
|
||||
version = "0.2.1"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61e4aac43f833fd637e429506cb2ac9d7df672c4b68f2eaaa163649b7fdc0444"
|
||||
checksum = "968ddca15e0fa74da3207aeb7b9fbbe94864dd13a17eaa95f75b5b836abf3007"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"regex",
|
||||
|
||||
+2
-3
@@ -41,9 +41,8 @@ flamescope = { version = "0.1", optional = true }
|
||||
[target.'cfg(not(target_os = "wasi"))'.dependencies]
|
||||
rustyline = "6.0"
|
||||
|
||||
|
||||
[dev-dependencies.cpython]
|
||||
version = "0.2"
|
||||
[dev-dependencies]
|
||||
cpython = "0.5.0"
|
||||
|
||||
[[bin]]
|
||||
name = "rustpython"
|
||||
|
||||
+26
-45
@@ -1,19 +1,20 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate cpython;
|
||||
extern crate rustpython_parser;
|
||||
extern crate rustpython_vm;
|
||||
extern crate test;
|
||||
|
||||
use rustpython_compiler::compile;
|
||||
use rustpython_vm::pyobject::PyResult;
|
||||
use rustpython_vm::VirtualMachine;
|
||||
|
||||
const MINIDOM: &str = include_str!("./benchmarks/minidom.py");
|
||||
const NBODY: &str = include_str!("./benchmarks/nbody.py");
|
||||
const MANDELBROT: &str = include_str!("./benchmarks/mandelbrot.py");
|
||||
|
||||
#[bench]
|
||||
fn bench_tokenization(b: &mut test::Bencher) {
|
||||
use rustpython_parser::lexer::{make_tokenizer, Tok};
|
||||
|
||||
let source = include_str!("./benchmarks/minidom.py");
|
||||
let source = MINIDOM;
|
||||
|
||||
b.bytes = source.len() as _;
|
||||
b.iter(|| {
|
||||
@@ -28,7 +29,7 @@ fn bench_tokenization(b: &mut test::Bencher) {
|
||||
fn bench_rustpy_parse_to_ast(b: &mut test::Bencher) {
|
||||
use rustpython_parser::parser::parse_program;
|
||||
|
||||
let source = include_str!("./benchmarks/minidom.py");
|
||||
let source = MINIDOM;
|
||||
|
||||
b.bytes = source.len() as _;
|
||||
b.iter(|| parse_program(source).unwrap())
|
||||
@@ -36,7 +37,7 @@ fn bench_rustpy_parse_to_ast(b: &mut test::Bencher) {
|
||||
|
||||
#[bench]
|
||||
fn bench_cpython_parse_to_ast(b: &mut test::Bencher) {
|
||||
let source = include_str!("./benchmarks/minidom.py");
|
||||
let source = MINIDOM;
|
||||
|
||||
let gil = cpython::Python::acquire_gil();
|
||||
let python = gil.python();
|
||||
@@ -55,10 +56,7 @@ fn bench_cpython_parse_to_ast(b: &mut test::Bencher) {
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cpython_nbody(b: &mut test::Bencher) {
|
||||
let source = include_str!("./benchmarks/nbody.py");
|
||||
|
||||
fn bench_cpython(b: &mut test::Bencher, source: &str) {
|
||||
let gil = cpython::Python::acquire_gil();
|
||||
let python = gil.python();
|
||||
|
||||
@@ -71,54 +69,37 @@ fn bench_cpython_nbody(b: &mut test::Bencher) {
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cpython_nbody(b: &mut test::Bencher) {
|
||||
bench_cpython(b, NBODY)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cpython_mandelbrot(b: &mut test::Bencher) {
|
||||
let source = include_str!("./benchmarks/mandelbrot.py");
|
||||
bench_cpython(b, MANDELBROT)
|
||||
}
|
||||
|
||||
let gil = cpython::Python::acquire_gil();
|
||||
let python = gil.python();
|
||||
fn bench_rustpy(b: &mut test::Bencher, name: &str, source: &str) {
|
||||
// NOTE: Take long time.
|
||||
let vm = VirtualMachine::default();
|
||||
|
||||
let globals = None;
|
||||
let locals = None;
|
||||
let code = vm
|
||||
.compile(source, compile::Mode::Exec, name.to_owned())
|
||||
.unwrap();
|
||||
|
||||
b.iter(|| {
|
||||
let res: cpython::PyResult<()> = python.run(source, globals, locals);
|
||||
assert!(res.is_ok());
|
||||
let scope = vm.new_scope_with_builtins();
|
||||
let res: PyResult = vm.run_code_obj(code.clone(), scope);
|
||||
vm.unwrap_pyresult(res);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rustpy_nbody(b: &mut test::Bencher) {
|
||||
// NOTE: Take long time.
|
||||
let source = include_str!("./benchmarks/nbody.py");
|
||||
|
||||
let vm = VirtualMachine::default();
|
||||
|
||||
let code = vm
|
||||
.compile(source, compile::Mode::Exec, "<stdin>".to_owned())
|
||||
.unwrap();
|
||||
|
||||
b.iter(|| {
|
||||
let scope = vm.new_scope_with_builtins();
|
||||
let res: PyResult = vm.run_code_obj(code.clone(), scope);
|
||||
vm.unwrap_pyresult(res);
|
||||
})
|
||||
bench_rustpy(b, "nbody.py", NBODY)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rustpy_mandelbrot(b: &mut test::Bencher) {
|
||||
// NOTE: Take long time.
|
||||
let source = include_str!("./benchmarks/mandelbrot.py");
|
||||
|
||||
let vm = VirtualMachine::default();
|
||||
|
||||
let code = vm
|
||||
.compile(source, compile::Mode::Exec, "<stdin>".to_owned())
|
||||
.unwrap();
|
||||
|
||||
b.iter(|| {
|
||||
let scope = vm.new_scope_with_builtins();
|
||||
let res: PyResult = vm.run_code_obj(code.clone(), scope);
|
||||
vm.unwrap_pyresult(res);
|
||||
})
|
||||
bench_rustpy(b, "mandelbrot.py", MANDELBROT)
|
||||
}
|
||||
Reference in new issue
Block a user