The Synchronous Blog

A blog about reactive programming languages.

Stress-testing Céu with SDL

with one comment

For a glimpse at the runtime costs of Céu, I created a simple application with SDL that animates 10000 rectangles on the screen.

My hypothesis is that lines of execution in Céu (a.k.a trails) are cheap and should be used carelessly, even for simple activities such as waiting for a single event and terminating. This way, the testing application in Céu has a peek of 40000 trails active at the same time, which are all visited by the scheduler on every frame.

I compare the implementation in Céu with a simpler application in C to serve as a benchmark.

The application in raw C is damn simple:

  • Declares a vector of 10000 rectangles.
  • Initializes each to 10×10 width/height, a random (x,y) position, and a random x velocity.
  • Animates them continuously, restarting from left when reaching the right side of the screen.
  • Achieved FPS = 120 .

The video shows the expected behavior, and the code, the full implementation.
(The video was adapted to 5000 rectangles to enable screencasting).

The application in Céu is considerably more complex (video and code):

  • The program has 5 lines of execution:
    1. On SDL_QUIT event: terminates the application.
    2. Every frame: clears the screen.
    3. Every 40ms: creates 30 new Rect organisms.
      • after 30s: kills all of them at once and restart the process
    4. Every frame: updates the screen.
    5. Every second: calculates the FPS.

    (technically they are 7 lines of execution because (3) and (5) are split in two)

  • The class Rect has 4 lines of execution:
    1. Every 200ms: varies the rectangle width, height, r, g, b (with a random epsilon).
    2. Every frame: animates the rectangle respecting its velocity, terminating when it reaches the end of the screen.
    3. Every frame: redraws the rectangle on screen.
    4. On termination: runs a simple finalizer (which maintains the number of organisms alive).
  • Achieved FPS = 107 . (when 10000 rectangles are on screen)

The main differences between the two implementations are marked in bold above and are summarized as follows:

  • The rectangles in Céu are allocated dynamically: in the peek, we have 750 rectangles being allocated (in the left side) and reclaimed (in the right side) every second.
  • Each rectangle on screen (10000 at most) has 4 active trails, all of which are visited by the scheduler every frame (4 x 10000 = 40000 lightweight threads active at the same time).
  • Finally, every 30 seconds the program restarts the spawning loop, killing all 10000 active organisms at once, running the associated finalizers, and reclaiming all memory.

Céu is a source-to-source compiler that generates single-threaded ansi-C code. This way, the generated code for the test application, although incomprehensible, can be compiled with gcc and tested in any computer that has SDL2:

  % gcc download_code.c -lSDL2


The simple SDL application in C is used as a benchmark to compare to a more complex application written in Céu, which shows a decrease around 10% in FPS.

Although the application in C could be re-implemented to achieve the same functionality (for a more strict comparison), the initial numbers are already satisfactory and make the point that the trail-oriented programming style of Céu is realistic, even in a highly dynamic scenario.


Written by francisco

June 6, 2013 at 12:04 am

One Response

Subscribe to comments with RSS.

  1. Hello, this weekend is nice designed for me, since this moment i am reading this enormous educational post here at my residence.

    Blaine Osmun

    May 25, 2016 at 10:28 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: