On MacOS & iOS, __thread variable is 35% faster than using pthread_getspecific. 

getSpecific cost: 0.000649
getTLS cost: 0.000423


- (void)test {
    double t1 = CFAbsoluteTimeGetCurrent();
    for (int i = 0; i < 100000; i++) {
        [self getSpecific];
    }
    double t2 = CFAbsoluteTimeGetCurrent();
    
    printf("getSpecific cost: %f\n", t2 - t1);
    
    double t3 = CFAbsoluteTimeGetCurrent();

    for (int i = 0; i < 100000; i++) {
        [self getTLS];
    }
    double t4 = CFAbsoluteTimeGetCurrent();
    printf("getTLS cost: %f\n", t4 - t3);

}

- (int)getSpecific {
    int * value = pthread_getspecific(tlsKey);
    return *value;
}
- (int)getTLS {
    return *tlv_v5;
}
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/KTHAKNENSBKURE7I2SRVXEPJ6NDNCACI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to