[vlc-devel] [PATCH] Trivial benchmark for vlc_memset and vlc_memcpy

Rémi Denis-Courmont remi at remlab.net
Wed Aug 19 22:42:14 CEST 2009


---
 src/libvlc.c |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/libvlc.c b/src/libvlc.c
index 9dc80c6..b88f712 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -287,6 +287,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
     return p_libvlc;
 }
 
+#include <sys/mman.h>
 /**
  * Initialize a libvlc instance
  * This function initializes a previously allocated libvlc instance:
@@ -784,6 +785,50 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
      */
     priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", false );
 
+    void *d;
+    const void *s;
+    const size_t size = 256*1024*1024;
+    s = mmap(NULL, size, PROT_READ, MAP_PRIVATE|MAP_POPULATE|MAP_ANON, -1, 0);
+    d = mmap(NULL, size, PROT_WRITE, MAP_PRIVATE|MAP_POPULATE|MAP_ANON, -1, 0);
+    assert (d != MAP_FAILED);
+
+#define diff(e, s) \
+    e.tv_sec -= s.tv_sec; \
+    if (e.tv_nsec < s.tv_nsec) { e.tv_sec--; e.tv_nsec += 1000000000; } \
+    e.tv_nsec -= s.tv_nsec; \
+    printf("%lu.%09lu\n", e.tv_sec, e.tv_nsec)
+
+    struct timespec t1, t2, t3;
+    for (unsigned i = 0; i < 10; i++)
+    {
+        clock_gettime( CLOCK_THREAD_CPUTIME_ID, &t1 );
+        memset(d, 0, size);
+        barrier();
+        clock_gettime( CLOCK_THREAD_CPUTIME_ID, &t2 );
+        vlc_memset(d, 0, size);
+        barrier();
+        clock_gettime( CLOCK_THREAD_CPUTIME_ID, &t3 );
+        printf("NS:");
+        diff(t3, t2);
+        printf("OS:");
+        diff(t2, t1);
+    }
+
+    for (unsigned i = 0; i < 10; i++)
+    {
+        clock_gettime( CLOCK_THREAD_CPUTIME_ID, &t1 );
+        memcpy(d, s, size);
+        barrier();
+        clock_gettime( CLOCK_THREAD_CPUTIME_ID, &t2 );
+        vlc_memcpy(d, s, size);
+        barrier();
+        clock_gettime( CLOCK_THREAD_CPUTIME_ID, &t3 );
+        printf("NC:");
+        diff(t3, t2);
+        printf("OC:");
+        diff(t2, t1);
+    }
+
     priv->b_stats = config_GetInt( p_libvlc, "stats" ) > 0;
     priv->i_timers = 0;
     priv->pp_timers = NULL;
-- 
1.6.3.3




More information about the vlc-devel mailing list