Challenge me to do ANYTHING computing/OS-related that you're also willing to do.
DFS
Challenge me to do ANYTHING computing/OS-related that you're also willing to do.
Put 2 million random dates in RAM:
// 0.852 Seconds. 1999-05-09, 2031-06-17, 2021-09-11, 1977-08-11, 2021-02-21,
const int NumDates = 2000000, StartYear = 1970, Years = 100, szDate = 12 ; wchar_t *Out, *D; D = Out = MallocTmp( NumDates*szDate*szChr + szChr ); __int64 Sec, TotalSecs, Min, Max ;
tm Rec, rTimeB = {}, rTimeE ;
rTimeB.tm_mday = 1, rTimeB.tm_year = StartYear - 1900, rTimeB.tm_isdst = -1 ; rTimeE = rTimeB, rTimeE.tm_year += Years ;
Min = mktime( &rTimeB ), Max = mktime( &rTimeE ), TotalSecs = Max - Min ; double Mark = UpSecs ;
LoopJ(NumDates) { Sec = Min + float(TotalSecs)*rand()/RAND_MAX ;
Rec = *localtime( ( time_t * ) &Sec ); D += swprintf( D, L"%d-%02d-%02d, ",
Rec.tm_year + 1900, Rec.tm_mon, Rec.tm_mday ); }
Out[5*szDate] = 0, Sh( L"%.3f Seconds. %s", UpSecs - Mark, Out );
Put 2 million random dates in RAM:
// 0.852 Seconds. 1999-05-09, 2031-06-17, 2021-09-11, 1977-08-11, 2021-02-21,
Out[5*szDate] = 0, Sh( L"%.3f Seconds. %s", UpSecs - Mark, Out );
We need the whole working program.
DFS
Challenge me to do ANYTHING computing/OS-related that you're also willing to do.
Put 2 million random dates in RAM:
// 0.852 Seconds. 1999-05-09, 2031-06-17, 2021-09-11, 1977-08-11, 2021-02-21,
const int NumDates = 2000000, StartYear = 1970, Years = 100, szDate = 12 ; wchar_t *Out, *D; D = Out = MallocTmp( NumDates*szDate*szChr + szChr ); __int64 Sec, TotalSecs, Min, Max ;
tm Rec, rTimeB = {}, rTimeE ;
rTimeB.tm_mday = 1, rTimeB.tm_year = StartYear - 1900, rTimeB.tm_isdst = -1 ; rTimeE = rTimeB, rTimeE.tm_year += Years ;
Min = mktime( &rTimeB ), Max = mktime( &rTimeE ), TotalSecs = Max - Min ; double Mark = UpSecs ;
LoopJ(NumDates) { Sec = Min + float(TotalSecs)*rand()/RAND_MAX ;
Rec = *localtime( ( time_t * ) &Sec ); D += swprintf( D, L"%d-%02d-%02d, ",
Rec.tm_year + 1900, Rec.tm_mon, Rec.tm_mday ); }
Out[5*szDate] = 0, Sh( L"%.3f Seconds. %s", UpSecs - Mark, Out );
int main(int argc, char *argv[])
{
int rdates = atoi(argv[1]);
int startYear = atoi(argv[2]);
int endYear = atoi(argv[3]);
On 12/31/23 15:02, DFS wrote:
int main(int argc, char *argv[])
{
int rdates = atoi(argv[1]);
int startYear = atoi(argv[2]);
int endYear = atoi(argv[3]);
Shouldn't you check argc to prevent a segfault when running with fewer arguments?
int daysRange = 365 * (endYear - startYear + 1);
int secsYear = 86400;
int *datearray = malloc( sizeof(int) * rdates );
struct tm sdt = {0,0,0,1,0,(startYear-1900)};
time_t sdts = mktime(&sdt);
time_t rsecs = sdts + (secsYear * (rand() % daysRange));
datearray[i] = rsecs;
$ randomdates 2000000 2020 2030
1999996. 2020-06-09 Tue
1999997. 2027-03-05 Fri
1999998. 2030-07-30 Tue
1999999. 2023-04-28 Fri
2000000. 2023-11-12 Sun
0.02s to generate 2000000 random dates in the years 2020 to 2030
On 12/31/2023 6:20 PM, candycanearter07 wrote:
On 12/31/23 15:02, DFS wrote:
int main(int argc, char *argv[])
{
int rdates = atoi(argv[1]);
int startYear = atoi(argv[2]);
int endYear = atoi(argv[3]);
Shouldn't you check argc to prevent a segfault when running with fewer
arguments?
If it was public-facing code I would put in validations, some help, a version, a date, and a public domain declaration.
I am curious about the randomness of the data. I may add some code to
write the data to a SQLite table and do some querying against it.
On 12/31/23 18:10, DFS wrote:
I am curious about the randomness of the data. I may add some code to
write the data to a SQLite table and do some querying against it.
Fair enough.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 10:51:05 |
Calls: | 6,706 |
Files: | 12,236 |
Messages: | 5,350,857 |