[Bug 2101201] Re: The performance of the rand() function degradation
Haixiao Yan
2101201 at bugs.launchpad.net
Tue Mar 11 03:38:02 UTC 2025
run 20.04 docker on ubuntu 22.04:
wrlbuild at 0ebf1418845d:/mnt/meta-test/recipes-example/example/files$ time ./mallocrandfree
Running malloc-rand-free test - creating 1,000 byte buffers 2,000,000 times.
real 0m28.753s
user 0m28.750s
sys 0m0.002s
wrlbuild at 0ebf1418845d:/mnt/meta-test/recipes-example/example/files$ cat /etc/issue
Ubuntu 20.04.5 LTS \n \l
ubuntu at haixiao:~/meta-test/recipes-example/example/files$ time ./mallocrandfree
Running malloc-rand-free test - creating 1,000 byte buffers 2,000,000 times.
real 0m46.971s
user 0m46.969s
sys 0m0.001s
ubuntu at haixiao:~/meta-test/recipes-example/example/files$ cat /etc/issue
Ubuntu 22.04.4 LTS \n \l
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to glibc in Ubuntu.
https://bugs.launchpad.net/bugs/2101201
Title:
The performance of the rand() function degradation
Status in glibc package in Ubuntu:
Incomplete
Bug description:
The performance of the rand() function on Ubuntu 22.04 has decreased by 62% compared to Ubuntu 21.04.
Measured on Ubuntu 21.04: 28.070s
Measured on Ubuntu 22.04: 45.493s
Ubuntu 22.04:
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# hyperfine ./mallocrandfree
Benchmark 1: ./mallocrandfree
Time (mean ± σ): 45.493 s ± 0.229 s [User: 45.489 s, System: 0.001 s]
Range (min … max): 45.246 s … 45.858 s 10 runs
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# uname -a
Linux ubuntu 6.5.0-18-generic #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.6) 2.35
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
Ubuntu 21.04:
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# hyperfine ./mallocrandfree
Benchmark 1: ./mallocrandfree
Time (mean ± σ): 28.070 s ± 0.162 s [User: 28.069 s, System: 0.001 s]
Range (min … max): 27.772 s … 28.362 s 10 runs
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# uname -a
Linux ubuntu 5.11.0-16-generic #17-Ubuntu SMP Wed Apr 14 20:12:43 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# ldd --version
ldd (Ubuntu GLIBC 2.33-0ubuntu5) 2.33
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# gcc --version
gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Here is the test code.
#cat mallocrandfree.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
void init()
{
// Tell the user what we are doing.
printf("Running malloc-rand-free test - creating 1,000 byte buffers 2,000,000 times.\n");
fflush(stdout);
// Seed the random number generator with the current time.
srand(time(NULL));
}
void loop()
{
for (int i = 0; i < 2000000; ++i)
{
//char* bufferPtr = malloc(1000);
char bufferPtr[1000];
for (int j = 0; j < 1000; ++j)
{
bufferPtr[j] = rand() % 256;
//bufferPtr[j] = j;
}
//free(bufferPtr);
}
}
void cleanup()
{
exit(0);
}
int main()
{
init();
loop();
cleanup();
}
Also can measured with time:
root at ubuntu:/home/ubuntu/meta-test/recipes-example/example/files# time ./mallocrandfree
Running malloc-rand-free test - creating 1,000 byte buffers 2,000,000 times.
real 0m45.613s
user 0m45.602s
sys 0m0.008s
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/2101201/+subscriptions
More information about the foundations-bugs
mailing list