user3081123
user3081123

Reputation: 435

Programm works faster in graphic shell than in command shell

I'm using a Raspberry Pi model B with a raspbian and kernel 3.18. What I do is just going through a loop with execution calculation.

Loop function looks like this.

for(;;) {
   Timer.get_dt();
   ...some print stuff...
}

and Timer.get_dt() is:

oldtime_ = time_;
clock_gettime(CLOCK_MONOTONIC, &time_);
Timer.dt = ((static_cast<int64_t>(time_.tv_sec) * 1000000000 + static_cast<int64_t>(time_.tv_nsec)) - (static_cast<int64_t>(oldtime_.tv_sec) * 1000000000 + static_cast<int64_t>(oldtime_.tv_nsec))) / 1000000000.0;

when I run code from command shell, I get loop running at 300-350 Hz. When I go startx and open a graphic shell, open a terminal and run code from there, I get hundreds times bigger frequency which seems much more believable.

What can cause command shell run program so slow?

Upvotes: 1

Views: 80

Answers (1)

It depends if you are using the command shell thru ssh or by plugging a physical screen device into your board.

Some virtual consoles have a baud limitation; so the kernel might try to imitate some slow terminal (including its speed). And virtual consoles (and any other tty-s) are traditionally slow.

You might use stty to understand and modify your terminal settings (in your virtual console).

BTW, it is probable that if you redirect the stdout (and/or stderr) output to some file, your program would go faster.

Upvotes: 4

Related Questions