Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny optimization of StatsEntry._log_response_time #2470

Merged
merged 4 commits into from
Nov 17, 2023

Conversation

lailongwei
Copy link
Contributor

Optimize a statistical code

@cyberw
Copy link
Collaborator

cyberw commented Nov 17, 2023

I’m not sure this code is faster… and it is less readable to me. (This comment was in regard to your second commit, the first one looks nice)

@lailongwei
Copy link
Contributor Author

I’m not sure this code is faster… and it is less readable to me. (This comment was in regard to your second commit, the first one looks nice)

first time commit is OK(I think so, haha).
second time is actually make code unreadable, I will be rollback later.
third time commit, I tested performance, the performance is not much difference, I will be rollback too, the simple(and temporary) test code:

# coding: utf-8

import time
import random
from collections import OrderedDict

test_seq = []
test_od_size = 1000
test_times = 10000
test_od = OrderedDict()
for i in range(test_od_size):
    test_od[i] = random.randint(1, 100)
    test_seq.append(i)


random.shuffle(test_seq)


sum_val = 0
beg_pc = time.perf_counter()
for i in range(test_times):
    for idx in test_seq:
        if idx in test_od:
            sum_val += test_od[idx]
print(f'cost time:{time.perf_counter() - beg_pc}')  # 1.5xx

test_time_idx = 0
beg_pc = time.perf_counter()
for i in range(test_times):
    for idx in test_seq:
        sum_val += test_od.get(idx, 0)
print(f'cost time:{time.perf_counter() - beg_pc}')  # 1.5xx

@cyberw cyberw changed the title Update stats.py Tiny optimization of StatsEntry._log_response_time Nov 17, 2023
@cyberw cyberw merged commit 93117eb into locustio:master Nov 17, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants