Skip to content

Commit

Permalink
Add: Benchmarks against assimp
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Nov 11, 2023
1 parent cb07b2e commit 99102f2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
4 changes: 3 additions & 1 deletion include/fastgltf/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,9 @@ namespace fastgltf {
* Returns the size, in bytes,
* @return
*/
[[nodiscard]] inline std::size_t getBufferSize() const noexcept;
[[nodiscard]] inline std::size_t getBufferSize() const noexcept {
return dataSize;
}

[[nodiscard]] explicit operator span<std::byte>() {
return span<std::byte>(bufferPointer, dataSize);
Expand Down
4 changes: 0 additions & 4 deletions src/fastgltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3212,10 +3212,6 @@ bool fg::GltfDataBuffer::loadFromFile(const fs::path& path, std::uint64_t byteOf
std::memset(bufferPointer + dataSize, 0, allocatedSize - dataSize);
return true;
}

std::size_t fg::GltfDataBuffer::getBufferSize() const noexcept {
return dataSize;
}
#pragma endregion

#pragma region AndroidGltfDataBuffer
Expand Down
12 changes: 12 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ if (FASTGLTF_ENABLE_GLTF_RS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gltf-rs/src/
target_compile_definitions(fastgltf_tests PRIVATE HAS_GLTFRS=1)
endif()

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gltf_loaders/assimp")
message(STATUS "fastgltf: Found assimp")
# Only enable glTF importer
set(ASSIMP_NO_EXPORT ON CACHE BOOL "")
set(ASSIMP_BUILD_TESTS OFF CACHE BOOL "")
set(ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT OFF CACHE BOOL "")
set(ASSIMP_BUILD_GLTF_IMPORTER ON CACHE BOOL "")
add_subdirectory(gltf_loaders/assimp)
target_link_libraries(fastgltf_tests PRIVATE assimp::assimp)
target_compile_definitions(fastgltf_tests PRIVATE HAS_ASSIMP=1)
endif()

add_source_directory(TARGET fastgltf_tests FOLDER ".")
38 changes: 38 additions & 0 deletions tests/benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ void setTinyGLTFCallbacks(tinygltf::TinyGLTF& gltf) {
#include "gltf-rs-bridge/lib.h"
#endif

#ifdef HAS_ASSIMP
#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/Base64.hpp>
#endif

std::vector<uint8_t> readFileAsBytes(std::filesystem::path path) {
std::ifstream file(path, std::ios::ate | std::ios::binary);
if (!file.is_open())
Expand Down Expand Up @@ -129,6 +135,12 @@ TEST_CASE("Benchmark loading of NewSponza", "[gltf-benchmark]") {
return rust::gltf::run(slice);
};
#endif

#ifdef HAS_ASSIMP
BENCHMARK("Parse NewSponza with assimp") {
return aiImportFileFromMemory(reinterpret_cast<const char*>(bytes.data()), jsonData->getBufferSize(), 0, nullptr);
};
#endif
}

TEST_CASE("Benchmark base64 decoding from glTF file", "[gltf-benchmark]") {
Expand Down Expand Up @@ -175,6 +187,14 @@ TEST_CASE("Benchmark base64 decoding from glTF file", "[gltf-benchmark]") {
return rust::gltf::run(slice);
};
#endif

#ifdef HAS_ASSIMP
BENCHMARK("2CylinderEngine with assimp") {
const auto* scene = aiImportFileFromMemory(reinterpret_cast<const char*>(bytes.data()), jsonData->getBufferSize(), 0, nullptr);
REQUIRE(scene != nullptr);
return scene;
};
#endif
}

TEST_CASE("Benchmark raw JSON parsing", "[gltf-benchmark]") {
Expand Down Expand Up @@ -220,6 +240,12 @@ TEST_CASE("Benchmark raw JSON parsing", "[gltf-benchmark]") {
return rust::gltf::run(slice);
};
#endif

#ifdef HAS_ASSIMP
BENCHMARK("Parse Buggy.gltf with assimp") {
return aiImportFileFromMemory(reinterpret_cast<const char*>(bytes.data()), jsonData->getBufferSize(), 0, nullptr);
};
#endif
}

TEST_CASE("Benchmark massive gltf file", "[gltf-benchmark]") {
Expand Down Expand Up @@ -269,6 +295,12 @@ TEST_CASE("Benchmark massive gltf file", "[gltf-benchmark]") {
return rust::gltf::run(slice);
};
#endif

#ifdef HAS_ASSIMP
BENCHMARK("Parse Bistro with assimp") {
return aiImportFileFromMemory(reinterpret_cast<const char*>(bytes.data()), jsonData->getBufferSize(), 0, nullptr);
};
#endif
}

TEST_CASE("Compare parsing performance with minified documents", "[gltf-benchmark]") {
Expand Down Expand Up @@ -357,6 +389,12 @@ TEST_CASE("Compare base64 decoding performance", "[gltf-benchmark]") {
};
#endif

#ifdef HAS_ASSIMP
BENCHMARK("Run Assimp's base64 decoder") {
return Assimp::Base64::Decode(generatedData);
};
#endif

BENCHMARK("Run fastgltf's fallback base64 decoder") {
return fastgltf::base64::fallback_decode(generatedData);
};
Expand Down

0 comments on commit 99102f2

Please sign in to comment.