Skip to content

Commit

Permalink
Formatted Python code using Ruff. (#16)
Browse files Browse the repository at this point in the history
Also formatted C code in the README using Clang formatter.
  • Loading branch information
tfpf authored Apr 25, 2024
1 parent dd05058 commit 514d3c6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ Put the following code in a file `example.c`:
#include <hdrbg.h>
#include <stdio.h>

int main(void)
int
main(void)
{
hdrbg_init(0);
for(int i = 0; i < 10; ++i)
for (int i = 0; i < 10; ++i)
{
long long unsigned r = hdrbg_rand(NULL);
printf("%llu\n", r);
Expand Down
7 changes: 4 additions & 3 deletions benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#! /usr/bin/env python3

import math
import hdrbg
import time
import timeit

import hdrbg


def benchmark(stmt, number, passes=32):
delay = math.inf
for _ in range(passes):
delay_ = timeit.timeit(stmt=stmt, number=number, timer=time.perf_counter_ns)
delay = min(delay, delay_)
result = delay / number / 1000
print(f'{stmt.__name__:>20} {result:8.2f} µs')
print(f"{stmt.__name__:>20} {result:8.2f} µs")


def main():
Expand All @@ -23,5 +24,5 @@ def main():
benchmark(hdrbg.real, 800)


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions examples/Python/thread-safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
print(hdrbg.fill(64).hex())

for _ in range(4):
print(hdrbg.rand(), end=' ')
print(hdrbg.rand(), end=" ")
for _ in range(4):
print(hdrbg.real(), end=' ')
print(hdrbg.real(), end=" ")
print()
24 changes: 13 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from setuptools import Extension, find_packages, setup
from setuptools import Extension, setup

ext_modules = [Extension(
name='hdrbg',
sources=['lib/pyhdrbg.c', 'lib/hdrbg.c', 'lib/sha256.c', 'lib/extras.c'],
include_dirs=['include'],
py_limited_api=True,
)]
kwargs = dict(
package_dir={'': 'lib'},
ext_modules=ext_modules,
)
ext_modules = [
Extension(
name="hdrbg",
sources=["lib/pyhdrbg.c", "lib/hdrbg.c", "lib/sha256.c", "lib/extras.c"],
include_dirs=["include"],
py_limited_api=True,
)
]
kwargs = {
"package_dir": {"": "lib"},
"ext_modules": ext_modules,
}
setup(**kwargs)

0 comments on commit 514d3c6

Please sign in to comment.