Git Product home page Git Product logo

gopybench's Introduction

gopybench: Memory Usage and Performance For Object Creation: Go vs Python

gopybench contains implementations in both Go and Python, designed to assess memory usage and performance across the entire lifecycle of object creation, initialization, and utilization.

Sample Object

All the tests are performed on sample object Person with:

  • members:
    • strings: First Name and Last Name,
    • integer: Age
  • methods:
    • Get Full Name, returning string where First and Last Names merged,
    • Increase Age, where Age is increased by 1

Go Implementation

sample.go implements a Go program that iteratively creates instances of a Person struct, including associated methods, while monitoring memory allocation and timing with following approaches:

  • single thread
  • multiple threads, where the number of threads equals the number of cores

Python Implementation

Python program sample.py with lib.py implements a logic that achieves the same task as the Go implementation using the following approaches:

  • object creation via:
    • default manner: Person in bench.sh output below
    • __slots__ enabled: PersonSlots
    • dataobject from recordclass: PersonDataObject
  • execution with:
    • single thread/process
    • multiple threads
    • multiple processes
  • with different interpreters:
    • Python, CPython 3.12
    • Cython, 3.0.10 with libc.pyx converted from lib.py
    • Pypy, 3.10.14

bench.sh shorten output for 4,000,000 objects created

=== GOLANG
golang: single thread 530.055568ms
golang: multiple threads 396.051268ms
=== PYTHON
Person object creation: single thread 5.23 seconds
Person object creation: 2 threads 5.22 seconds
Person object creation: 2 processes 2.53 seconds
PersonSlots object creation: single thread 4.61 seconds
PersonSlots object creation: 2 threads 4.60 seconds
PersonSlots object creation: 2 processes 2.20 seconds
PersonDataObject object creation: single thread 2.43 seconds
PersonDataObject object creation: 2 threads 2.41 seconds
PersonDataObject object creation: 2 processes 1.27 seconds
=== CYTHON
Person object creation: single thread 3.22 seconds
Person object creation: 2 threads 3.19 seconds
Person object creation: 2 processes 1.74 seconds
PersonSlots object creation: single thread 3.16 seconds
PersonSlots object creation: 2 threads 3.26 seconds
PersonSlots object creation: 2 processes 1.73 seconds
PersonDataObject object creation: single thread 3.20 seconds
PersonDataObject object creation: 2 threads 3.26 seconds
PersonDataObject object creation: 2 processes 1.65 seconds
=== PYPY
Person object creation: single thread 1.61 seconds
Person object creation: 2 threads 1.47 seconds
Person object creation: 2 processes 1.67 seconds
PersonSlots object creation: single thread 1.60 seconds
PersonSlots object creation: 2 threads 1.45 seconds
PersonSlots object creation: 2 processes 1.67 seconds
PersonDataObject object creation: single thread 1.59 seconds
PersonDataObject object creation: 2 threads 1.43 seconds
PersonDataObject object creation: 2 processes 1.66 seconds

Conclusion

Based on the benchmark results comparing memory usage and performance for object creation between Go and Python implementations, several key findings emerged:

  • Go:

    • multiple threads implementation showcased the best timing, completing in 0.396 seconds.
  • Python:

    • dataobject from the recordclass library with multiple processes achieved the best timing for default Python interpreter, completing in 1.27 seconds,
    • __slots__ and dataobjects implementations didn't significantly impact timing for both Cython and Pypy,
    • Cython with multi-process implementations were found to be more efficient than its other approaches,
    • Pypy with multithreaded implementation showed better performance than its other approaches.

These results underscore the efficiency of Go's concurrency model, particularly in multi-threaded scenarios. However, Python demonstrates competitive performance and can be further optimized through strategic techniques such as leveraging multiple processes with dataobject from recordclass for default interpreter.

gopybench's People

Contributors

gglluukk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.