OK, maybe I'm not configued right, but here's the thing:
In VS 2022 build tools CLI this code fread()s a 3.9GB file into memory in 1.5 secs, so that's 2581.5 MB/sec for almost 4GB.
In Pelles-C using IDE, the same code fread()s the same 3.9GB file into memory in 12.8 secs, so that's 307.1 MB/sec.
I'm gonna drop my code here so you guys can play with it, but that's a pretty big discrepancy...I was tearing my hair out (what little is left) while working with this in Pelles, then decided to try it in VS 2022 to see if it was something I was coding wrong or my machine was just slow, turns out it was the compiler after all...by several orders of magnitude (1.5 vs 12.8 secs).
OS: Win10 build 19045
Machine: Xeon, 64GB, 2TB SSD system drive
Test File: Avatar.The.Way.Of.Water.mp4
File Size: 3941952295
Compiler settings:
-Pelles C 12.00.2-
Debug: None
Warnings: level 1
Diagnostics: Classic
Microsoft Extensions Yes
Multithreaded Yes
Maximise speed Yes
inlining: Default
Architecture: SSE2
Floating Point: Fast
Calling Conv: __cdecl
Linker: kernel32.lib advapi32.lib delayimp64.lib user32.lib
Compiler settings:
-VS 2022 Build Tools-
All default, no libs added, no compiler-flags
command line: cl dde.c
Try it with a file of around the same size (I limit the size to 4GB in the code).
See what you come up with, I'd like to know why it's doing that, as I'm sure you would too.
Drop me a line if you think of any other info I can provide.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#define MEG 1000000.0
#define GIG 1000000000.0
#define MAXLEN 4294967295
#define MEMERR -100
#define LENERR -200
#define FILERR -300
#define FRDERR -400
#define NOERR 0
#define uchar unsigned char
struct {
uchar *fbuf;
uchar *ip;
uchar *op;
uint32_t addr;
uint32_t sz;
double et;
}M;
//parse errors
///////////////////////////////////////////////////////////////
char *geterror(uint32_t e)
{
static char ebuf[32];
switch(e){
case MEMERR:
strcpy(ebuf,"\nMEMERR\n");
break;
case LENERR:
strcpy(ebuf,"\nLENERR\n");
break;
case FILERR:
strcpy(ebuf,"\nFILERR\n");
break;
case FRDERR:
strcpy(ebuf,"\nFRDERR\n");
break;
default:
strcpy(ebuf,"\nNOERR\n");
break;
}
return ebuf;
}
//get filesize up to MAXLEN
///////////////////////////////////////////////////////////////
uint32_t getfsize(char *fname)
{
FILE *fp;
__int64 offsetzed=0;
__int64 offsetend=0;
fp=fopen(fname,"rb");
_fseeki64(fp, offsetzed, SEEK_END);
offsetend = _ftelli64(fp);
fclose(fp);
if(offsetend>MAXLEN) return LENERR;
M.sz=(uint32_t)offsetend;
return M.sz;
}
//load input file into memory
///////////////////////////////////////////////////////////////
uint32_t loadinput(char *fname)
{
FILE *fp;
uint32_t fsize =0;
uint32_t r =0;
clock_t t;
fsize=getfsize(fname);
if(fsize==LENERR) return LENERR;
M.fbuf =(uchar *)malloc((fsize+10) * sizeof(char));
if(M.fbuf==NULL) return MEMERR;
memset(M.fbuf,0,(fsize+10));
fp=fopen(fname,"rb");
if(fp==NULL) return FILERR;
t = clock();
r=(uint32_t)fread(M.fbuf,1,fsize,fp); //// slow fread! ////
t = clock() - t;
M.et = ((double)t)/CLOCKS_PER_SEC; //// elapsed time ////
fclose(fp);
if(r!=fsize){
printf ("fread error: r:%u, fsize:%u\n",r,fsize);
}
return r;
}
// MAIN
///////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
uint32_t r=0;
if(argc<2){
printf("Syntax: dde filename\n");
return 0;
}
r=loadinput(argv[1]);
if(r!=M.sz){
printf(" %s\n",geterror(r));
free(M.fbuf);
return 0;
}
printf(" fread() took %.1f seconds to read a %.1fGB file.\n", M.et,(float) M.sz/GIG);
printf(" That's %.1fMB per sec. \n",(M.sz/(float)M.et)/MEG);
free(M.fbuf);
return 0;
}