{"id":23524202,"url":"https://github.com/alxbilger/sofabenchmark","last_synced_at":"2025-04-19T22:52:33.337Z","repository":{"id":42038249,"uuid":"362117764","full_name":"alxbilger/SofaBenchmark","owner":"alxbilger","description":"A Sofa application to benchmark Sofa code using google benchmark","archived":false,"fork":false,"pushed_at":"2025-02-19T08:33:35.000Z","size":106,"stargazers_count":4,"open_issues_count":2,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T13:51:11.976Z","etag":null,"topics":["benchmark","sofa-framework"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alxbilger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-27T13:14:18.000Z","updated_at":"2025-02-19T08:33:39.000Z","dependencies_parsed_at":"2024-03-21T11:06:12.359Z","dependency_job_id":null,"html_url":"https://github.com/alxbilger/SofaBenchmark","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxbilger%2FSofaBenchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxbilger%2FSofaBenchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxbilger%2FSofaBenchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxbilger%2FSofaBenchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alxbilger","download_url":"https://codeload.github.com/alxbilger/SofaBenchmark/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249824537,"owners_count":21330334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","sofa-framework"],"created_at":"2024-12-25T18:14:57.974Z","updated_at":"2025-04-19T22:52:33.318Z","avatar_url":"https://github.com/alxbilger.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SofaBenchmark\nA [Sofa](https://github.com/sofa-framework/sofa) application to benchmark [Sofa](https://github.com/sofa-framework/sofa) code using [google benchmark](https://github.com/google/benchmark)\n\n## Introduction\n\nThis application must be compiled along with Sofa (https://github.com/sofa-framework/sofa). It is used to benchmark code from [Sofa](https://github.com/sofa-framework/sofa).\n\n## Compilation\n\n### Prerequisites\n\n- Being able to build Sofa: https://www.sofa-framework.org/community/doc/\n- git\n- CMake\n\n### Instructions\n\nTo add the SofaBenchmark target to the Sofa solution:\n- Clone SofaBenchmark somewhere on your system\n- At the same level, if it's not done yet, create `CMakeLists.txt`\n- In `CMakeLists.txt`, add the following line: `sofa_add_application(SofaBenchmark SofaBenchmark)`\n- Enter the path where you cloned SofaBenchmark in the Sofa CMake variable `SOFA_EXTERNAL_DIRECTORIES` (see https://www.sofa-framework.org/community/doc/plugins/build-a-plugin-from-sources/)\n- Run CMake\n- SofaBenchmark should appear as a new target\n\n## Code Example\n\nThe application uses the micro-benchmarking library google benchmark (https://github.com/google/benchmark). See the repository [readme](https://github.com/google/benchmark#readme) for generic examples.\n\nThe following example benchmarks the call to `NarrowPhaseDetection::getDetectionOutputs`\n```c++\nvoid BM_NarrowPhaseDetection_getDetectionOutputs(benchmark::State \u0026state)\n{\n    for (auto _ : state)\n    {\n        state.PauseTiming();\n\n        auto narrowPhaseDetection = New\u003csofa::component::collision::EmptyNarrowPhaseDetection\u003e();\n\n        sofa::helper::vector\u003csofa::component::collision::PointCollisionModel\u003csofa::defaulttype::Vec3Types\u003e::SPtr\u003e collisionModels;\n        for (unsigned int i = 0; i \u003c state.range(0); ++i)\n        {\n            collisionModels.push_back(New\u003csofa::component::collision::PointCollisionModel\u003csofa::defaulttype::Vec3Types\u003e \u003e());\n        }\n\n        state.ResumeTiming();\n        for (auto a : collisionModels)\n        {\n            for (auto b : collisionModels)\n            {\n                narrowPhaseDetection-\u003egetDetectionOutputs(a.get(), b.get());\n            }\n        }\n    }\n}\n```\n\n## Output\n\nThe benchmark of `NarrowPhaseDetection::getDetectionOutputs` defined in the previous section gives the following output:\n\n```\n------------------------------------------------------------------------------------------\nBenchmark                                                Time             CPU   Iterations\n------------------------------------------------------------------------------------------\nBM_NarrowPhaseDetection_getDetectionOutputs/8         38.1 us         38.1 us        17905\nBM_NarrowPhaseDetection_getDetectionOutputs/16         241 us          241 us         2860\nBM_NarrowPhaseDetection_getDetectionOutputs/32        1423 us         1423 us          498\nBM_NarrowPhaseDetection_getDetectionOutputs/64        8453 us         8454 us           87\nBM_NarrowPhaseDetection_getDetectionOutputs/128      44993 us        44994 us           15\nBM_NarrowPhaseDetection_getDetectionOutputs/256     238668 us       238664 us            3\n```\n\n## Benchmark SOFA Scenes\n\nA second application is available: SofaBenchmarkScenes.\nIt must be enabled in CMake with the variable `SOFABENCHMARK_BUILD_BENCH_SCENES`.\nWhile SofaBenchmark focus on code snippet, this application is specific to benchmark entire SOFA scenes.\n\nSeveral types of scene benchmarks are available:\n- `BM_Scene_bench_SimulationFactor`: executes `n` times the same simulation with a fixed number of time steps\n- `BM_Scene_bench_AdvancedTimer`: executes the simulation once with a number of time steps provided as a parameter. Also access `AvancedTimer`.\n- `BM_Scene_bench_StepFactor`: executes the simulation once with a number of time steps provided as a parameter.\n\n### Output\n\nAn example of output for SofaBenchmarkScenes is:\n\n```\n-------------------------------------------------------------------------------------------------------------------\nBenchmark                                                         Time             CPU   Iterations UserCounters...\n-------------------------------------------------------------------------------------------------------------------\nBM_Scene_bench_SimulationFactor\u003cSparseLDLSolverScene\u003e/2        1583 ms         1562 ms            1 FPS=128/s frame=7.8125ms\nBM_Scene_bench_SimulationFactor\u003cSparseLDLSolverScene\u003e/4        3192 ms         3219 ms            1 FPS=124.272/s frame=8.04688ms\nBM_Scene_bench_SimulationFactor\u003cSparseLDLSolverScene\u003e/8        6325 ms         6281 ms            1 FPS=127.363/s frame=7.85156ms\nBM_Scene_bench_SimulationFactor\u003cSparseLDLSolverScene\u003e/16      12743 ms        12766 ms            1 FPS=125.337/s frame=7.97852ms\nBM_Scene_bench_StepFactor\u003cSparseLDLSolverScene\u003e/512            3940 ms         3906 ms            1 FPS=131.072/s frame=7.62939ms\nBM_Scene_bench_StepFactor\u003cSparseLDLSolverScene\u003e/1024           7810 ms         7781 ms            1 FPS=131.598/s frame=7.59888ms\nBM_Scene_bench_StepFactor\u003cSparseLDLSolverScene\u003e/2048          15717 ms        15719 ms            1 FPS=130.29/s frame=7.67517ms\n\n```\n\n### AdvancedTimer\n\nSOFA has a mechanism of measuring its performances using the class `AdvancedTimer` (https://www.sofa-framework.org/community/doc/programming-with-sofa/api-overview/advanced-timer/).\nThe timers can be identified using labels.\nA generic benchmark template is available in SofaBenchmark allowing to execute a SOFA simulation, measures its total duration and also access a list of `AdvancedTimer` to report them as a [custom counter](https://github.com/google/benchmark/blob/main/docs/user_guide.md#custom-counters).\nSee this example:\n```cpp\nvoid BM_SparseLDLSolver(benchmark::State\u0026 state)\n{\n    BM_Scene_bench_AdvancedTimer\u003cSparseLDLSolverScene\u003e(state, {\"MBKBuild\", \"MBKSolve\"});\n}\n```\n\nThe scene is defined in the struct `SparseLDLSolverScene`.\nIn addition to the scene, a couple of `AdvancedTimer` is also reported: `MBKBuild` and `MBKSolve`.\n\n#### Output\n\n```\n----------------------------------------------------------------------------------------------\nBenchmark                                    Time             CPU   Iterations UserCounters...\n----------------------------------------------------------------------------------------------\nBM_SparseLDLSolver/50/iterations:10        202 ms          200 ms           10 FPS=250/s MBKBuild=556.384u MBKSolve=3.27496m frame=4ms\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falxbilger%2Fsofabenchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falxbilger%2Fsofabenchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falxbilger%2Fsofabenchmark/lists"}