# Hash-Based Random-Integer `operator[]` Insert Timing Test

## Description

This test inserts a number of values with uniform i.i.d. integer keys into a container, using `operator[]`. It measures the average time for `operator[]` as a function of the number of values inserted.

(The test was executed with `hash_random_int_subscript_insert_timing_test` 200 200 2100)

## Purpose

The test primarily checks the effect of different underlying hash-tables (see Design::Associative Containers::Associative Containers::Hash-Based Containers).

## Results

Figures NCCG, NCCM, and NCCL show the results for the native and collision-chaining types in g++, MSVC++, and local, respectively; Figures NGPG, NGPM, and NGPL show the results for the native and probing types in g++, msvc++, and local respectively; Figures CCGPG, CCGPM, and CCGPL compare the results for the collision-chaining and probing types of `pb_ds` only, in g++, MSVC++, and local respectively.

######

NCCG: Native and collision-chaining hash random int insert timing test using `operator` - g++

In the above figure, the names in the legends have the following meaning:

1. cc_hash_mod_prime_nea_lc_1div8_1div2_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2
2. n_hash_map_ncah- `std::tr1::unordered_map` with `cache_hash_code` = `false`
3. cc_hash_mask_exp_nea_lc_1div8_1div2_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2
4. cc_hash_mod_prime_nea_lc_1div8_1div1_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/1
5. cc_hash_mask_exp_nea_lc_1div8_1div1_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/1

######

NCCM: Native and collision-chaining hash random int insert timing test using `operator` - msvc++

In the above figure, the names in the legends have the following meaning:

1. n_hash_map_ncah- `stdext::hash_map`
2. cc_hash_mod_prime_nea_lc_1div8_1div2_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2
3. cc_hash_mod_prime_nea_lc_1div8_1div1_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/1
4. cc_hash_mask_exp_nea_lc_1div8_1div2_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2
5. cc_hash_mask_exp_nea_lc_1div8_1div1_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/1

######

NCCL: Native and collision-chaining hash random int insert timing test using `operator` - local

######

NGPG: Native and probing hash random int insert timing test using `operator` - g++

In the above figure, the names in the legends have the following meaning:

1. gp_hash_mod_quadp_prime_nea_lc_1div8_1div2_nsth_map- `gp_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2, and `Probe_Fn` = `quadratic_probe_fn`
2. n_hash_map_ncah- `std::tr1::unordered_map` with `cache_hash_code` = `false`
3. gp_hash_mask_linp_exp_nea_lc_1div8_1div2_nsth_map- `gp_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2, and `Probe_Fn` = `linear_probe_fn`

######

NGPM: Native and probing hash random int insert timing test using `operator` - msvc++

In the above figure, the names in the legends have the following meaning:

1. n_hash_map_ncah- `stdext::hash_map`
2. gp_hash_mod_quadp_prime_nea_lc_1div8_1div2_nsth_map- `gp_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2, and `Probe_Fn` = `quadratic_probe_fn`
3. gp_hash_mask_linp_exp_nea_lc_1div8_1div2_nsth_map- `gp_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2, and `Probe_Fn` = `linear_probe_fn`

######

NGPL: Native and probing hash random int insert timing test using `operator` - local

######

CCGPG: Collision-chaining and probing hash random int insert timing test using `operator` - g++

In the above figure, the names in the legends have the following meaning:

1. gp_hash_mod_quadp_prime_nea_lc_1div8_1div2_nsth_map- `gp_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2, and `Probe_Fn` = `quadratic_probe_fn`
2. cc_hash_mod_prime_nea_lc_1div8_1div2_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2
3. cc_hash_mask_exp_nea_lc_1div8_1div2_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2
4. gp_hash_mask_linp_exp_nea_lc_1div8_1div2_nsth_map- `gp_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2, and `Probe_Fn` = `linear_probe_fn`

######

CCGPM: Collision-chaining and probing hash random int insert timing test using `operator` - msvc++

In the above figure, the names in the legends have the following meaning:

1. cc_hash_mod_prime_nea_lc_1div8_1div2_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2
2. cc_hash_mask_exp_nea_lc_1div8_1div2_nsth_map- `cc_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , and `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2
3. gp_hash_mod_quadp_prime_nea_lc_1div8_1div2_nsth_map- `gp_hash_table` with `Comb_Hash_Fn` = `direct_mod_range_hashing` , `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_prime_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2, and `Probe_Fn` = `quadratic_probe_fn`
4. gp_hash_mask_linp_exp_nea_lc_1div8_1div2_nsth_map- `gp_hash_table` with `Comb_Hash_Fn` = `direct_mask_range_hashing` , `Resize_Policy` = `hash_standard_resize_policy` with `Size_Policy` = `hash_exponential_size_policy` , and `Trigger_Policy` = `hash_load_check_resize_trigger` with αmin = 1/8 and αmax = 1/2, and `Probe_Fn` = `linear_probe_fn`

######

CCGPL: Collision-chaining and probing hash random int insert timing test using `operator` - local

## Observations

In this setting, as in Hash-Based Text `find` Find Timing Test and Hash-Based Random-Integer `find` Find Timing Test , the choice of underlying hash-table underlying hash-table (see Design::Associative Containers::Hash-Based Containers ) affects performance most, then the range-hashing scheme (See Design::Associative Containers::Hash-Based Containers::Hash Policies ), and, only finally, other policies.

There are some differences, however:

1. In this setting, probing tables function sometimes more efficiently than collision-chaining tables (see Figures CCGPG and CCGPM ). This is explained shortly.
2. The performance graphs have a "saw-tooth" shape. The average insert time rises and falls. As values are inserted into the container, the load factor grows larger. Eventually, a resize occurs. The reallocations and rehashing are relatively expensive. After this, the load factor is smaller than before.

Collision-chaining containers use indirection for greater flexibility; probing containers store values contiguously, in an array (see Figure Motivation::Different underlying data structures A and B, respectively). It follows that for simple data types, probing containers access their allocator less frequently than collision-chaining containers, (although they still have less efficient probing sequences). This explains why some probing containers fare better than collision-chaining containers in this case.

Within each type of hash-table, the range-hashing scheme affects performance more than other policies. This is similar to the situation in Hash-Based Text `find` Find Timing Test and Hash-Based Random-Integer `find` Find Timing Test. Unsurprisingly, however, containers with lower alphamax perform worse in this case, since more re-hashes are performed.

Observations::Hash-Based Container Types summarizes some observations on hash-based containers; Observations::Hash-Based Containers' Policies summarizes some observations on hash-based containers' policies.