Met my Muse

Meeting a living breathing broken Muse has lead to harm & self abuse. “Met my Muse” is published by Space Age Bonobo in Poets Unlimited.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Performance test for dictionary operation

Given 2 below implementations, I will test it from diferents perspectives.

the basic test:

The above functions, it tries to get a non-exist element, the catch is too much slower(overhead).

For the context above, it tries on a dict of 1.000 elements, the f2 gets the first element in the fastest way, but in case that often the key doesn’t exists in impact negative, because of catch overhead.

In the context above the test ran on a dict of 100.000 elements, for the first key it only increased 100ns, even for the last element the f1 function only increased 600ns.

the bigger dataset, increases the overall times, the gain of speed for ‘no check’ if ~5%.

CONCLUSION:

The implementation represented by f1 should be used in all cases, you may put the exception catch if it rarely ocurr.

Add a comment

Related posts:

LAS 101 Intern Experience

Coming into the semester I wasn’t really sure what to expect about being an LAS 101 Intern. I knew my major strengths were my ability to relate with different people, having vast knowledge and…