Skip to content

Commit

Permalink
This allows us to pass SIMDJSON_STRUCTURAL_INDEXER_STEP as a command-…
Browse files Browse the repository at this point in the history
…line option. (#2055)
  • Loading branch information
lemire committed Aug 25, 2023
1 parent 2e0a939 commit c969200
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
22 changes: 13 additions & 9 deletions benchmark/benchmarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ struct benchmarker {
return 100.0 * a / b;
}

void print(bool tabbed_output) const {
void print(bool tabbed_output, bool stage1_only) const {
if (tabbed_output) {
char* filename_copy = reinterpret_cast<char*>(malloc(strlen(filename)+1));
SIMDJSON_PUSH_DISABLE_WARNINGS
Expand Down Expand Up @@ -503,17 +503,21 @@ struct benchmarker {
stats->blocks_with_16_structurals_flipped, percent(stats->blocks_with_16_structurals_flipped, stats->blocks));
}
printf("\n");
printf("All Stages (excluding allocation)\n");
print_aggregate("| " , all_stages_without_allocation.best);
// frequently, allocation is a tiny fraction of the running time so we omit it
if(allocate_stage.best.elapsed_sec() > 0.01 * all_stages_without_allocation.best.elapsed_sec()) {
printf("|- Allocation\n");
print_aggregate("| ", allocate_stage.best);
if(!stage1_only) {
printf("All Stages (excluding allocation)\n");
print_aggregate("| " , all_stages_without_allocation.best);
// frequently, allocation is a tiny fraction of the running time so we omit it
if(allocate_stage.best.elapsed_sec() > 0.01 * all_stages_without_allocation.best.elapsed_sec()) {
printf("|- Allocation\n");
print_aggregate("| ", allocate_stage.best);
}
}
printf("|- Stage 1\n");
print_aggregate("| ", stage1.best);
printf("|- Stage 2\n");
print_aggregate("| ", stage2.best);
if(!stage1_only) {
printf("|- Stage 2\n");
print_aggregate("| ", stage2.best);
}
if (collector.has_events()) {
double freq1 = (stage1.best.cycles() / stage1.best.elapsed_sec()) / 1000000000.0;
double freq2 = (stage2.best.cycles() / stage2.best.elapsed_sec()) / 1000000000.0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/dom/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int main(int argc, char *argv[]) {
if (!options.verbose) { progress.erase(); }

for (size_t i=0; i<options.files.size(); i++) {
benchmarkers[i]->print(options.tabbed_output);
benchmarkers[i]->print(options.tabbed_output, options.stage1_only);
delete benchmarkers[i];
}

Expand Down
5 changes: 5 additions & 0 deletions cmake/developer-options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MACOSX_RPATH OFF)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(SIMDJSON_STRUCTURAL_INDEXER_STEP CACHE STRING "the SIMDJSON_STRUCTURAL_INDEXER_STEP variable")

if(SIMDJSON_STRUCTURAL_INDEXER_STEP)
message(STATUS "Setting SIMDJSON_STRUCTURAL_INDEXER_STEP to ${SIMDJSON_STRUCTURAL_INDEXER_STEP}.")
add_compile_definitions(SIMDJSON_STRUCTURAL_INDEXER_STEP=${SIMDJSON_STRUCTURAL_INDEXER_STEP})
endif()
# LTO seems to create all sorts of fun problems. Let us
# disable temporarily.
#include(CheckIPOSupported)
Expand Down
5 changes: 4 additions & 1 deletion src/generic/stage1/json_structural_indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ class bit_indexer {
#if SIMDJSON_PREFER_REVERSE_BITS
bits = reverse_bits(bits);
#endif

#ifdef SIMDJSON_STRUCTURAL_INDEXER_STEP
static constexpr const int STEP = SIMDJSON_STRUCTURAL_INDEXER_STEP;
#else
static constexpr const int STEP = 2;
#endif
static constexpr const int STEP_UNTIL = 24;

write_indexes_stepped<0, STEP_UNTIL, STEP>(idx, bits, cnt);
Expand Down

0 comments on commit c969200

Please sign in to comment.