Skip to content

Commit

Permalink
Merge pull request #35 from hit9/dev
Browse files Browse the repository at this point in the history
Added benchmark of stm32
  • Loading branch information
hit9 authored Feb 1, 2021
2 parents 86c8ea4 + 07d6c4d commit e7e1814
Show file tree
Hide file tree
Showing 73 changed files with 80,356 additions and 0 deletions.
29 changes: 29 additions & 0 deletions benchmark/stm32/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
default: build

bp:
bitproto c drone.bitproto bpbench/bp
cd bpbench && cp bp/*.h Core/Inc
cd bpbench && cp bp/*.c Core/Src

bp-optimization-mode:
bitproto c drone.bitproto bpbench/bp -O -F "Drone"
cd bpbench && cp bp/*.h Core/Inc
cd bpbench && cp bp/*.c Core/Src

build: bp
make -C bpbench

build-cc-o2: bp
make -C bpbench OPT=-O2

build-cc-o3: bp
make -C bpbench OPT=-O3

build-optimization-mode: bp-optimization-mode
make -C bpbench

build-optimization-mode-o2: bp-optimization-mode
make -C bpbench OPT=-O2

flash:
st-flash write ./bpbench/build/bpbench.bin 0x08000000
64 changes: 64 additions & 0 deletions benchmark/stm32/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
bitproto benchmark on STM32
===========================

This directory contains a simple benchmark for bitproto encoding and decoding on STM32.

The project `bpbench <bpbench>`_ is based on code generated by
`stm32cubemx <https://www.st.com/en/development-tools/stm32cubemx.html>`_ ,
tested on microcontrollers: `stm32f103zet6 <https://www.st.com/en/microcontrollers-microprocessors/stm32f103ze.html>`_
and `stm32f103ve6 <https://www.st.com/en/microcontrollers-microprocessors/stm32f103ve.html>`_.

Benchmark result
----------------

* Microcontroller: `STM32F103ZE <https://www.st.com/en/microcontrolles-microprocessors/stm32f103ze.html>`_,
Arm Cortex-M3 MCU, 72 MHz
* bitproto file: `drone.bitproto <drone.bitproto>`_.

Standard Mode
^^^^^^^^^^^^^

The "standard mode" means to run bitproto compiler **without**
the optimization mode flag ``-O``, that is to use `the bitproto c lib <../../lib/c>`_.

.. list-table::
:header-rows: 1

* - GCC Optimization Flag
- Number of calls
- Encode cost per call
- Decode cost per call
* - No ``-O``
- 10000
- 170μs
- 163μs
* - ``-O2``
- 10000
- 135μs
- 131μs
* - ``-O3``
- 10000
- 127μs
- 119μs

Optimization Mode
^^^^^^^^^^^^^^^^^

The "optimization mode" means to run bitproto compiler **with**
the optimization mode flag ``-O``, that is not to use `the bitproto c lib <../../lib/c>`_.

.. list-table::
:header-rows: 1

* - GCC Optimization Flag
- Number of calls
- Encode cost per call
- Decode cost per call
* - No ``-O``
- 10000
- 9μs
- 9μs
* - ``-O2``
- 10000
- 9μs
- 9μs
4 changes: 4 additions & 0 deletions benchmark/stm32/bpbench/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
BasedOnStyle: Google
IndentWidth: 4
---
6 changes: 6 additions & 0 deletions benchmark/stm32/bpbench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build
.mxproject
Core/Inc/*_bp.h
Core/Src/*_bp.c
bp/*_bp.c
bp/*_bp.h
72 changes: 72 additions & 0 deletions benchmark/stm32/bpbench/Core/Inc/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
void simple_printf(const char *fmt, ...);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Loading

0 comments on commit e7e1814

Please sign in to comment.