ODISSEI-School-Choice / school-choice

This Python implementation tries to model school choice and resulting school segregation based on the work of Schelling (1971) and Stoica & Flache (2014).
Apache License 2.0
0 stars 0 forks source link

Optimize performance of the step function of the simulation #8

Closed jiqicn closed 2 years ago

jiqicn commented 2 years ago

Possible bottlenecks:

jiqicn commented 2 years ago

Compared np.random.choice() with np.random.shuffle() and built-in random.shuffle().

image

The result suggests that np.random.shuffle() performs much better than the other two.

By switching to np.random.shuffle(), it indeed gains a significant improvement on runtime (5 to 7 seconds).

See code: https://github.com/ODISSEI-School-Choice/school-choice/blob/92cea49628a8d670c6f8d651315bc5a987e458ae/compass/origin/agents_household.py#L391