Index

lognestmonster / b54160c

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
17831 Jan 2020 20:10b54160cAdd test for linting C source filesJosh Stockin111G

Blob @ lognestmonster / tests / size.py

application/x-python1389 bytesdownload raw
1#!/usr/bin/env python3.7
2"""Compiles the base source for output speed and size tests using different optimization levels"""
3
4import subprocess
5import os
6
7PROJECT_PATH = os.path.abspath(
8 os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
9)
10HEADER_PATH = os.path.join(PROJECT_PATH, "src/c")
11TEST_FILE = os.path.join(PROJECT_PATH, "tests/base_header.c")
12OUT_FILE = os.path.join(PROJECT_PATH, "bin/performance")
13
14CC = "gcc"
15CFLAGS = ["-pedantic", "-Wall", "-Wextra", "-Werror"]
16COUTFLAG = "-o"
17COPTIMIZATIONS = ["-O0", "-O1", "-O2", "-O3", "-Os"]
18CINCLUDES = ["-I", HEADER_PATH]
19
20
21def gcc_compile(file_name: str, optimization_level: str = "-O0"):
22 """Uses gcc subprocess to compile at a set optimization level"""
23 process_command = (
24 [CC] + CFLAGS + CINCLUDES + [COUTFLAG, file_name, TEST_FILE, optimization_level]
25 )
26 process = subprocess.Popen(process_command)
27 process.wait() # wait for execution
28 if process.returncode:
29 raise Exception(f"gcc_compile: error in compilation")
30
31
32def get_size(file_name: str):
33 """Uses os.stat to get the file size in bytes of a specified file"""
34 return os.stat(file_name).st_size
35
36
37if __name__ == "__main__":
38 for optimization in COPTIMIZATIONS:
39 out_file = f"{OUT_FILE}{optimization}"
40 gcc_compile(out_file, optimization)
41 print(f"Level {optimization}: {get_size(out_file)}")
42