XanaDublaKublaConch / pysdtoken

A pythonic (?) ctypes wrapper for RSA SecurID Tokens

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

close_service Function - Slow to Execute

ssmithTaylor opened this issue · comments

The execution time of close_service() is rather long on Mac, On average I'm seeing around 2 seconds to execute.

I've noticed that if I add a breakpoint right before the call to the C API, then wait a few seconds, when I proceed the function executes and finishes very quickly. I'm not sure why this would be the case.

I'd be curious to see how it performs on other people's systems. To that end, I wrote a quick benchmarking script.

import pysdtoken
import time

count = 0
final_count = 5
avg_tt = 0.0
avg_ct = 0.0

while count < final_count:

    st = time.time()
    sd = pysdtoken.SDProcess()

    cts = time.time()
    sd.close_service()
    cte = time.time()
    et = time.time()

    tct = cte - cts
    tt = et - st

    avg_tt += tt
    avg_ct += tct

    print(f"Test #{count + 1}: Total Time: {tt} | Close Time: {tct}")
    count += 1

print(f"Total Time Avg: {avg_tt / final_count} | Close Time Avg: {avg_ct / final_count}")

Example output:

  • Windows (without a token)
Test #1: Total Time: 0.6615047454833984 | Close Time: 0.5024900436401367
Test #2: Total Time: 0.6069846153259277 | Close Time: 0.5006721019744873
Test #3: Total Time: 0.6115283966064453 | Close Time: 0.5024893283843994
Test #4: Total Time: 0.6078929901123047 | Close Time: 0.5015802383422852
Test #5: Total Time: 0.6242508888244629 | Close Time: 0.502490758895874
Total Time Avg: 0.6224323272705078 | Close Time Avg: 0.5019444942474365
  • Mac (with a single token)
Test #1: Total Time: 2.953191041946411 | Close Time: 2.512363910675049
Test #2: Total Time: 2.7152068614959717 | Close Time: 2.51251482963562
Test #3: Total Time: 2.693143129348755 | Close Time: 2.5085389614105225
Test #4: Total Time: 2.6996309757232666 | Close Time: 2.5180001258850098
Test #5: Total Time: 2.7025959491729736 | Close Time: 2.5183968544006348
Total Time Avg: 2.7527535915374757 | Close Time Avg: 2.5139629364013674

Edit:

It appears it's a fairly significant portion of the total execution time even on windows, I wonder why that would be.

It's possible this is just a limitation SecurID, or something funky with python + ctypes, I skipped execution of everything but what's required to open and close the service and it takes the same amount of time. I wonder if execution time is the same for the v4 and v5 windows client.

My test run: Win 10 64-bit, Python 3.7.0 32-bit, 1 Token with PIN

Test #1: Total Time: 1.0571458339691162 | Close Time: 0.5026555061340332
Test #2: Total Time: 0.663538932800293 | Close Time: 0.5029551982879639
Test #3: Total Time: 0.7041127681732178 | Close Time: 0.515620231628418
Test #4: Total Time: 0.6832351684570312 | Close Time: 0.5032083988189697
Test #5: Total Time: 0.6683387756347656 | Close Time: 0.5022170543670654
Total Time Avg: 0.7552742958068848 | Close Time Avg: 0.50533127784729

It's possible this is fixed on the new version. I made lots of changes to the code and the architecture. I don't have a mac to test on , so if you can check it out, feel free. It's now on pypy.

I can confirm there appears to be a marginal speed improvement of 0.1 seconds, but given the timespan it's possible that's due to external factors.