#!/bin/sh

# random 300 files
BENCH_FILES="Glaiveai2K---calculate_area_d82d93ba.json Github_easy---o25107.json Github_easy---o36571.json Glaiveai2K---create_calendar_event_45b0cdd1.json Glaiveai2K---calculate_area_da13baad.json Github_trivial---o85907.json Github_trivial---o60115.json Github_medium---o58620.json Github_easy---o83939.json Github_hard---o21383.json Github_medium---o74591.json Snowplow---sp_326_Normalized.json Github_easy---o88674.json Glaiveai2K---calculate_area_cb5fd3a6.json Github_medium---o74598.json Snowplow---sp_193_Normalized.json Github_medium---o82712.json Github_medium---o39166.json Github_hard---o21264.json JsonSchemaStore---vtesttree-schema.json Github_easy---o7375.json Glaiveai2K---find_hotel_cd6e97f8.json JsonSchemaStore---requirements.json Kubernetes---kb_300_Normalized.json Glaiveai2K---calculate_distance_a6a2b75a.json Github_hard---o13112.json WashingtonPost---wp_24_Normalized.json JsonSchemaStore---up.json Synthesized---draft2019_09_valid_patternProperties_id12_subschema1_not_2.json Github_trivial---o69753.json Github_trivial---o45633.json Github_easy---o57639.json Glaiveai2K---generate_invoice_214a7c51.json Github_easy---o5167.json Kubernetes---kb_237_Normalized.json Github_easy---o66297.json Github_trivial---o25159.json Kubernetes---kb_850_Normalized.json Kubernetes---kb_245_Normalized.json Github_easy---o44191.json Github_hard---o69965.json Github_easy---o63149.json Glaiveai2K---calculate_area_39e6c1c8.json Snowplow---sp_73_Normalized.json Github_easy---o9870.json Kubernetes---kb_855_Normalized.json Github_easy---o9953.json Github_hard---o30259.json Github_medium---o9965.json Github_easy---o73039.json Glaiveai2K---calculate_area_e73f4e16.json WashingtonPost---wp_31_Normalized.json Kubernetes---kb_873_Normalized.json Github_medium---o64611.json Synthesized---draft2019_09_nonvalid_not_id5_subschema1_not_2.json Snowplow---sp_37_Normalized.json Github_easy---o67175.json JsonSchemaStore---aerleon-policies.schema.json Glaiveai2K---calculate_area_371aa6f6.json Github_medium---o58602.json Github_trivial---o47925.json Github_medium---o6212.json Github_hard---o30477.json Github_medium---o85188.json Github_hard---o12278.json Kubernetes---kb_362_Normalized.json Glaiveai2K---calculate_area_d8d800a1.json Github_trivial---o58627.json Github_medium---o82647.json Github_easy---o42287.json Synthesized---draft2019_09_valid_boolean_schema_id17_subschema1_not_2.json WashingtonPost---wp_0_Normalized.json Kubernetes---kb_440_Normalized.json Github_hard---o5408.json Github_medium---o52958.json Synthesized---draft2019_09_nonvalid_ref_id3_subschema1_not_2.json Kubernetes---kb_868_Normalized.json Github_hard---o10293.json Glaiveai2K---generate_invoice_1e31c738.json Github_medium---o90913.json Github_easy---o64016.json Github_medium---o45282.json Github_medium---o81186.json Github_easy---o90886.json Github_easy---o45205.json Glaiveai2K---generate_random_password_139780fe.json Github_medium---o14076.json Snowplow---sp_273_Normalized.json Glaiveai2K---calculate_area_40768ee6.json Github_easy---o83726.json Github_hard---o66267.json Kubernetes---kb_717_Normalized.json Github_easy---o79442.json JsonSchemaStore---cypress.schema.json Synthesized---draft2019_09_nonvalid_const_id18_subschema1_not_2.json Github_easy---o7230.json Github_hard---o21359.json Snowplow---sp_267_Normalized.json Handwritten---oneofpr3.json Kubernetes---kb_29_Normalized.json Glaiveai2K---generate_invoice_a880dda9.json Glaiveai2K---create_calendar_event_d8598b2e.json Github_medium---o57757.json Kubernetes---kb_184_Normalized.json Glaiveai2K---search_product_c1db04b2.json Glaiveai2K---generate_random_password_7d9eef1f.json Github_medium---o90801.json Github_easy---o33825.json Github_medium---o60864.json Github_medium---o12289.json JsonSchemaStore---npm-badges.json Github_medium---o79492.json Kubernetes---kb_591_Normalized.json Glaiveai2K---calculate_area_4717c896.json Github_medium---o61635.json Synthesized---draft2019_09_valid_type_id68_subschema1_not_2.json Github_easy---o32480.json Github_medium---o17602.json Snowplow---sp_216_Normalized.json Github_ultra---o21136.json Kubernetes---kb_1100_Normalized.json Glaiveai2K---calculate_area_214862f8.json Kubernetes---kb_404_Normalized.json Glaiveai2K---book_hotel_e2c3dd06.json Glaiveai2K---calculate_area_668ac89b.json Glaiveai2K---calculate_area_a43aa172.json Glaiveai2K---calculate_area_8cdcc04b.json Kubernetes---kb_173_Normalized.json Github_easy---o54556.json Snowplow---sp_50_Normalized.json Synthesized---draft2019_09_valid_const_id26_subschema1_not_2.json Glaiveai2K---analyze_health_data_4ad104b4.json Github_easy---o21861.json Snowplow---sp_195_Normalized.json Glaiveai2K---create_invoice_d2546e08.json Github_hard---o58443.json Github_easy---o54986.json Glaiveai2K---calculate_area_ba84f5eb.json Synthesized---draft2019_09_nonvalid_patternProperties_id5_subschema1_not_2.json Github_medium---o79482.json Github_medium---o90290.json Glaiveai2K---search_recipes_fb66ed5b.json Github_easy---o40346.json Snowplow---sp_270_Normalized.json Github_easy---o9829.json Github_medium---o22092.json Github_hard---o42252.json Github_easy---o68322.json Glaiveai2K---generate_random_string_06f0edaa.json Glaiveai2K---calculate_area_5e5031a5.json Handwritten---oneof11.json Github_hard---o83132.json Kubernetes---kb_475_Normalized.json Github_hard---o8490.json Glaiveai2K---calculate_area_9861dcfd.json JsonSchemaStore---lintstagedrc.schema.json Github_trivial---o10020.json Github_medium---o33966.json Github_easy---o21860.json Github_medium---o9512.json Github_hard---o20272.json Kubernetes---kb_38_Normalized.json Kubernetes---kb_358_Normalized.json Snowplow---sp_303_Normalized.json Github_hard---o63369.json Kubernetes---kb_1041_Normalized.json Github_medium---o54544.json Github_easy---o6176.json Kubernetes---kb_144_Normalized.json Github_hard---o39444.json Github_hard---o54898.json Glaiveai2K---search_recipe_4a726de3.json Github_easy---o69844.json Github_easy---o51221.json Kubernetes---kb_378_Normalized.json Glaiveai2K---calculate_mortgage_payment_e133248d.json Github_hard---o41277.json Glaiveai2K---create_resume_4f5cf1f7.json Github_trivial---o65587.json Github_medium---o41348.json Github_easy---o68280.json Github_easy---o90335.json Github_hard---o21292.json Synthesized---draft2019_09_nonvalid_properties_id9_subschema1_not_2.json Github_medium---o28612.json Github_trivial---o12256.json Github_easy---o57168.json Github_trivial---o82286.json Github_easy---o30899.json Synthesized---draft2019_09_nonvalid_oneOf_id7_subschema1_not_2.json Snowplow---sp_136_Normalized.json Github_hard---o72527.json Github_medium---o90708.json Github_medium---o5798.json Github_easy---o89197.json Github_easy---o29023.json JsonSchemaStore---sourcehut-build-0.65.0.json Github_medium---o5223.json Github_medium---o60120.json Glaiveai2K---calculate_area_03267c14.json Github_trivial---o64859.json JsonSchemaStore---catalogue-entry-schema.json Kubernetes---kb_858_Normalized.json Github_medium---o65476.json Github_easy---o78064.json Github_easy---o90279.json Kubernetes---kb_366_Normalized.json Github_easy---o68337.json Snowplow---sp_131_Normalized.json Github_medium---o47239.json Github_easy---o68350.json Glaiveai2K---calculate_area_4966fc8a.json Github_easy---o53024.json Github_easy---o6202.json Github_easy---o41690.json Github_medium---o30701.json Github_hard---o17394.json Github_easy---o56015.json Github_medium---o72192.json Github_medium---o4850.json JsonSchemaStore---sprite.json Github_easy---o42284.json Kubernetes---kb_3_Normalized.json Github_easy---o31242.json Synthesized---draft2019_09_valid_type_id20_subschema1_not_2.json Snowplow---sp_201_Normalized.json Github_easy---o85199.json Glaiveai2K---find_hotel_14104de8.json Github_medium---o1262.json Synthesized---draft2019_09_valid_not_id8_subschema1_not_2.json Github_hard---o60990.json JsonSchemaStore---rust-project.json Github_hard---o38732.json Snowplow---sp_252_Normalized.json Github_hard---o82740.json Glaiveai2K---book_flight_9d21bbd6.json Synthesized---draft2019_09_nonvalid_const_id2_subschema1_not_2.json Glaiveai2K---calculate_discounted_price_87a78f03.json Glaiveai2K---schedule_meeting_9f5127d1.json Github_medium---o65452.json Github_easy---o30125.json Kubernetes---kb_671_Normalized.json Kubernetes---kb_665_Normalized.json Github_easy---o58637.json Github_ultra---o69209.json JsonSchemaStore---csscomb.json Github_easy---o68355.json Github_easy---o6265.json Glaiveai2K---generate_invoice_c245c9ab.json Glaiveai2K---calculate_area_32f30fb2.json Github_medium---o9766.json Glaiveai2K---generate_calendar_event_a37e2af9.json Github_hard---o50673.json Github_medium---o15201.json Github_medium---o83291.json Snowplow---sp_331_Normalized.json Kubernetes---kb_115_Normalized.json Github_medium---o57236.json Glaiveai2K---calculate_area_a577a04d.json Github_trivial---o62772.json Github_medium---o68301.json Handwritten---pnmp9.json Github_easy---o3617.json Github_easy---o53899.json Github_easy---o9951.json Github_medium---o84343.json Kubernetes---kb_661_Normalized.json Github_medium---o5475.json Github_hard---o9787.json Github_easy---o21460.json Github_easy---o79592.json Github_medium---o71328.json Github_medium---o27148.json Kubernetes---kb_1108_Normalized.json Github_easy---o91014.json Github_medium---o90651.json Github_medium---o38735.json Glaiveai2K---generate_random_password_c0d3f55c.json Github_hard---o21287.json Github_hard---o25806.json Github_easy---o5463.json Synthesized---draft2019_09_valid_const_id29_subschema1_not_2.json Github_hard---o60295.json Synthesized---draft2019_09_valid_properties_id3_subschema1_not_2.json Github_trivial---o69314.json Github_medium---o20476.json Github_medium---o9860.json Github_medium---o51161.json Github_easy---o20488.json Github_medium---o24621.json Glaiveai2K---search_hotels_9b0d362c.json Glaiveai2K---calculate_area_6d68167d.json Github_easy---o25970.json Synthesized---draft2019_09_valid_type_id73_subschema1_not_2.json Kubernetes---kb_331_Normalized.json JsonSchemaStore---sigrid-scope-file.schema.json Github_hard---o84205.json Github_easy---o9945.json Github_hard---o41252.json Github_easy---o81742.json"

for folder in ../.. .. ../../tmp ../../.. ; do
    if test -d $folder/jsonschemabench/maskbench/data; then
        MB_DATA=$folder/jsonschemabench/maskbench/data/
        break
    fi
done

if [ "$1" == "--bench" ] ; then
    shift
    DEFAULT_ARGS="--expected expected_maskbench.json --ballpark --num-threads 1 "
    for f in $BENCH_FILES; do
        DEFAULT_ARGS="$DEFAULT_ARGS $MB_DATA/$f"
    done
fi

if [ "$1" == "--exp" ] ; then
    shift
    DEFAULT_ARGS="--expected expected_maskbench.json"
fi

if [ -z "$PERF" ]; then
    cargo build --release
    ../target/release/json_stats $DEFAULT_ARGS "$@"
else
    PERF='perf record -F 9999 -g'
    RUSTFLAGS='-C force-frame-pointers=y' cargo build --profile perf
    $PERF ../target/perf/json_stats $DEFAULT_ARGS "$@"
    echo "perf report -g graph,0.05,caller"
    echo "perf report -g graph,0.05,callee"
fi

