Fast C++ String Output -


i have program outputs data fpga. since data changes extremely fast, i'm trying increase speed of program. right printing data this

for (int = 0; < 100; i++) {     printf("data: %d\n",getdata(i)); } 

i found using 1 printf increases speed

printf("data: %d \n data: %d \n data: %d \n",getdata(1),getdata(2),getdata(3)); 

however, can see, messy , can't use loop. tried concatenating strings first using sprintf , printing out @ once, it's slow first method. suggestions?

edit: i'm printing file first, because realized console scrolling issue. still slow. i'm debugging memory controller external fpga, closer real speed better.

if writing stdout, might not able influence all.

otherwise, set buffering

now, boost karma known pretty performant. however, i'd need know more input data.

meanwhile, try buffer writes manually: live on coliru

#include <stdio.h>  int getdata(int i) { return i; }  int main() {     char buf[100*24]; // or other nice, large enough size     char* const last = buf+sizeof(buf);     char* out = buf;      (int = 0; < 100; i++) {         out += snprintf(out, last-out, "data: %d\n", getdata(i));     }      *out = '\0';     printf("%s", buf); } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -