Skip to main content

Cache performance model

Project description

Lint > Tests > Publish codecov Documentation

Cache Performance Model

This project provides a model for simulating cache performance, including different cache configurations and replacement policies.

pip install cache-performance-model

Classes

Cache

Cache is an abstract base class for different cache models. It provides common functionality and properties for cache simulation.

DirectMappedCache

DirectMappedCache is a class for simulating a direct-mapped cache. It inherits from Cache and implements the read and write methods.

SetAssociativeCache

SetAssociativeCache is a class for simulating a set-associative cache. It inherits from Cache and implements the read and write methods. It supports different replacement policies such as RANDOM, FIFO, LRU, NMRU, and PLRU.

FullyAssociativeCache

FullyAssociativeCache is a class for simulating a fully associative cache. It inherits from Cache and implements the read and write methods. It supports different replacement policies such as RANDOM, FIFO, LRU, NMRU, and PLRU.

Examples

Direct Mapped Cache

from cache_performance_model.cache_model import DirectMappedCache

# Create a direct-mapped cache instance
cache = DirectMappedCache(cache_line_bytes=64, cache_size_kib=4)

# Perform read and write operations
cache.read(0x1A2B3C4D)
cache.write(0x1A2B3C4D)

# Print cache statistics
cache.stats()

Set Associative Cache

from cache_performance_model.cache_model import SetAssociativeCache
from cache_performance_model.types import ReplacementPolicy

# Create a set-associative cache instance with LRU replacement policy
cache = SetAssociativeCache(cache_line_bytes=64, cache_size_kib=4, n_way=4, replacement_policy=ReplacementPolicy.LRU)

# Perform read and write operations
cache.read(0x1A2B3C4D)
cache.write(0x1A2B3C4D)

# Print cache statistics
cache.stats()

Fully Associative Cache

from cache_performance_model.cache_model import FullyAssociativeCache
from cache_performance_model.types import ReplacementPolicy

# Create a fully associative cache instance with RANDOM replacement policy
cache = FullyAssociativeCache(cache_line_bytes=64, cache_size_kib=4, replacement_policy=ReplacementPolicy.RANDOM)

# Perform read and write operations
cache.read(0x1A2B3C4D)
cache.write(0x1A2B3C4D)

# Print cache statistics
cache.stats()

Installation

To install the required dependencies, run:

pip install -r requirements.txt

Documentation

To build the documentation, run:

nox -s docs

The HTML pages will be in docs/_build/html.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cache_performance_model-0.1.5.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cache_performance_model-0.1.5-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file cache_performance_model-0.1.5.tar.gz.

File metadata

  • Download URL: cache_performance_model-0.1.5.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.9

File hashes

Hashes for cache_performance_model-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9a5d932fb148409f77554b8bee951cee4f151f8bf60747578387e61617655efc
MD5 696351939006b2cc2b1c602382ed15e1
BLAKE2b-256 6b5bb133416606ea430bce1d307dcf9c2bfd49607372d6ea866771e57e64e996

See more details on using hashes here.

File details

Details for the file cache_performance_model-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for cache_performance_model-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ca8efebbae6ac7a31471dcc505592413bf2036d9f62789e48312b51dcdc7eca9
MD5 8b2eee72552574945ac3689d30a0cfeb
BLAKE2b-256 c06f8ca303150acc1add3d5cf857dd69ae126a549e795a82bc0f75429a85e0ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page