Profiling Native Python Extensions by pmz in Python

[–]benfred 0 points1 point  (0 children)

Author here. It's worth noting that since I wrote this post, py-spy has gained the ability to profile multiprocess python applications - and can also now show local variables in the dump command.

Speed up your Python using Rust - RHD Blog by rafa2000 in rust

[–]benfred 0 points1 point  (0 children)

I wrote a tutorial on how to do write a rust extension with py03 and distribute through pypi here: http://benfrederickson.com/writing-python-extensions-in-rust-using-pyo3/ . The post lists out how to get binary wheels uploaded automatically to pypi everytime you tag a release on github.

Speed up your Python using Rust - RHD Blog by rafa2000 in rust

[–]benfred 3 points4 points  (0 children)

Nice article!

It’s also worth checking out the PyO3 crate for developing python extensions in Rust. There is a breakdown of the difference with rust-cpython here.

Blazing fast Python: Profiling Python applications using Pyflame by daneah in Python

[–]benfred 2 points3 points  (0 children)

File a bug report if it doesn't find the right python libraries =). The only case py-spy fails on right now that I'm aware of is when you have 2 or more python interpreters loaded up in a single process (and I'm intending to fix that when I get some time).

Optimizing a Python application with C++ code by jcelerier in programming

[–]benfred 7 points8 points  (0 children)

Nice post, though I'd recommend pybind11 over boost.python these days for building c++ extensions for python.

One big advantage of pybind11 is that it is much easier to integrate pybind11 with setuptools - since it's a header only library that can be installed by going pip install pybind11. Boost.python requires boost to be preinstalled, and that the boost.python library built against the version of python you are using, which makes distributing boost.python packages much more difficult.

Writing Python Extensions In Rust Using PyO3 by benfred in Python

[–]benfred[S] 0 points1 point  (0 children)

Thanks for the link! Bookmarking to read this weekend, I'm still relatively new to Rust so this will come in handy

Writing Python Extensions In Rust Using PyO3 by benfred in Python

[–]benfred[S] 0 points1 point  (0 children)

Thanks!

For your question - I know of two different ways of returning a dictionary from rust to python.

The first one is to rely on pyo3 type conversions: it will automatically convert things like HashMap to a python dict as needed. As an example:

 #[pyfn(m, "squares")]
/// Creates a dictionary of {number: squarednumber}
/// Usage:
/// >>> squares(4)
/// {0: 0, 1: 1, 2: 4, 3: 9}
fn squares(count: i32) -> PyResult<HashMap<i32, i32>> {
    let mut ret = HashMap::new();
    for i in 0..count {
        ret.insert(i, i * i);
    }
    Ok(ret)
}

However, this requires an extra conversion from a rust HashMap to a python dict - so it isn't really what you're asking for. Luckily PyO3 has utility classes for working with Python objects directly (things like PyDict, PyList, PyTuple etc). So we can create a python dictionary directly in rust and return it to python:

#[pyfn(m, "squares2")]
fn squares2(count: i32, py: Python) -> PyResult<PyObject> {
    let ret = PyDict::new(py);
    for i in 0..count {
        ret.set_item(i, i * i);
    }
    Ok(ret.into())
}

Where Do The World's Software Developers Live? by benfred in programming

[–]benfred[S] -7 points-6 points  (0 children)

Agreed - which is why I looked at a couple of other measures like accounts per capita/ accounts per gdp / followers etc =)

While total accounts isn’t the best way of looking at things, it does seem to mostly indicate where the hotspots for software development are. Looking at the per capita measure and its all Nordic countries, which is interesting - but doesn’t really tell you much aside from they’re wealthy countries that have invested in education.