@@ -46,6 +46,7 @@ static void test_perf(void); // issue #1104
4646static void test_perf2 (void ); // issue #1104
4747static void test_perf3 (void ); // issue #1104
4848static void test_perf4 (void ); // issue #1104
49+ static void test_perf5 (void ); // issue #1104
4950
5051#if _WIN32
5152#include " main-override-dep.h"
@@ -64,7 +65,8 @@ int main() {
6465 // test_perf();
6566 // test_perf2();
6667 // test_perf3();
67- test_perf4 ();
68+ // test_perf4();
69+ test_perf5 ();
6870
6971 // test_std_string();
7072 // test_thread_local();
@@ -627,4 +629,41 @@ static void test_perf4(void) {
627629 for (auto & th : threads) {
628630 th.join ();
629631 }
630- }
632+ }
633+
634+
635+ void escape5 (uint8_t * p, size_t n) {
636+ if (n==0 ) return ;
637+ for (size_t i = 0 ; i < n; i++) {
638+ p[i] = (uint8_t )(i & 0xFF );
639+ }
640+ p[rand () % n] = (uint8_t )(n&0xFF );
641+ // asm volatile("" : : "g"(p) : "memory");
642+ }
643+
644+ static long gsum5;
645+
646+ static void local_alloc5 () {
647+ long sum = 0 ;
648+ for (int i = 0 ; i < 500000 ; i++) {
649+ const size_t n = i % 1000 ;
650+ uint8_t * p = (uint8_t *)mi_malloc (n);
651+ escape5 (p, n);
652+ if (i % 4 > 0 ) {
653+ if (n>0 ) { sum += p[n-1 ]; }
654+ mi_free (p);
655+ }
656+ }
657+ gsum5 += sum;
658+ }
659+
660+ static void test_perf5 (void ) {
661+ std::vector<std::thread> threads;
662+ for (int i = 1 ; i <= 100 ; ++i) {
663+ threads.emplace_back (std::thread (&local_alloc5));
664+ }
665+ for (auto & th : threads) {
666+ th.join ();
667+ }
668+ printf (" gsum5: %li\n " , gsum5);
669+ }
0 commit comments