From patchwork Fri Mar 20 22:10:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vesely X-Patchwork-Id: 6061311 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26817BF90F for ; Fri, 20 Mar 2015 22:10:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A7EF204D1 for ; Fri, 20 Mar 2015 22:10:36 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D6F7D203EC for ; Fri, 20 Mar 2015 22:10:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E2E796E3CA; Fri, 20 Mar 2015 15:10:31 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qg0-f42.google.com (mail-qg0-f42.google.com [209.85.192.42]) by gabe.freedesktop.org (Postfix) with ESMTP id D059F6E3B6 for ; Fri, 20 Mar 2015 15:10:30 -0700 (PDT) Received: by qgew92 with SMTP id w92so29671648qge.2 for ; Fri, 20 Mar 2015 15:10:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=qZW9FK3WpTPbwLKl24Q4153iSjL2urjElRYiLsNWV4U=; b=lGETJgI5aCQ9c8H5UxuIxUSccvC97tzzNrxCWC0Saac6heIkmE9PW61sb/lZfBGYAu /uNpsnXJI3ojY5/RT20WgVtISKwvdEk0ygkkyxd1YKnRO0pNoVG4iLUMsuwCtC8RaNCP Q+96bNP6j7L+frv0rwDRtV+beMffUSSH+ASkiZgzb282X1XjlKj99TWVNJ0t9vATfzZN AMu5myv/MhEdSEenW5ywBm32GEQWq2nOW/2h6XNR5s4ypZV6uG+fse5k65ur4Q2G0yzR 5pLF1thC+ojCxY/YzQIFHw0vOCTz7dTAgcgNVoSx708oifIMkWfgEiMnTV8A9xY8fz5a gfqQ== X-Gm-Message-State: ALoCoQmW1OmV7UV9OXfXfKIphwqx6Yole/PJnPdTDczijwUsh03e1IJAElDfLOdLbDBR4e7PL4pW X-Received: by 10.229.95.74 with SMTP id c10mr104757753qcn.17.1426889430398; Fri, 20 Mar 2015 15:10:30 -0700 (PDT) Received: from adriatix.rutgers.edu ([198.151.130.140]) by mx.google.com with ESMTPSA id b69sm3928946qka.11.2015.03.20.15.10.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Mar 2015 15:10:30 -0700 (PDT) From: Jan Vesely To: dri-devel@lists.freedesktop.org, Emil Velikov Subject: [PATCH libdrm 2/4] drmSL: Split tests to a separate file Date: Fri, 20 Mar 2015 18:10:26 -0400 Message-Id: <1426889428-4847-2-git-send-email-jan.vesely@rutgers.edu> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1426889428-4847-1-git-send-email-jan.vesely@rutgers.edu> References: <1426889428-4847-1-git-send-email-jan.vesely@rutgers.edu> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jan Vesely Acked-by: Emil Velikov --- .gitignore | 1 + tests/Makefile.am | 3 +- tests/drmsltest.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 tests/drmsltest.c diff --git a/.gitignore b/.gitignore index 06cc928..9c6ecd7 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,7 @@ via.kld tests/auth tests/dristat tests/drmstat +tests/drmsltest tests/getclient tests/getstats tests/getversion diff --git a/tests/Makefile.am b/tests/Makefile.am index 10f54e3..ca0f3c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -59,7 +59,8 @@ TESTS = \ getstats \ setversion \ updatedraw \ - name_from_fd + name_from_fd \ + drmsltest check_PROGRAMS += $(TESTS) diff --git a/tests/drmsltest.c b/tests/drmsltest.c new file mode 100644 index 0000000..d193008 --- /dev/null +++ b/tests/drmsltest.c @@ -0,0 +1,172 @@ +/* xf86drmSL.c -- Skip list support + * Created: Mon May 10 09:28:13 1999 by faith@precisioninsight.com + * + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: Rickard E. (Rik) Faith + * + * DESCRIPTION + * + * This file contains a straightforward skip list implementation.n + * + * FUTURE ENHANCEMENTS + * + * REFERENCES + * + * [Pugh90] William Pugh. Skip Lists: A Probabilistic Alternative to + * Balanced Trees. CACM 33(6), June 1990, pp. 668-676. + * + */ + +#include +#include +#include + +#include "xf86drm.h" + +static void print(void* list) +{ + unsigned long key; + void *value; + + if (drmSLFirst(list, &key, &value)) { + do { + printf("key = %5lu, value = %p\n", key, value); + } while (drmSLNext(list, &key, &value)); + } +} + +static double do_time(int size, int iter) +{ + void *list; + int i, j; + unsigned long keys[1000000]; + unsigned long previous; + unsigned long key; + void *value; + struct timeval start, stop; + double usec; + void *ranstate; + + list = drmSLCreate(); + ranstate = drmRandomCreate(12345); + + for (i = 0; i < size; i++) { + keys[i] = drmRandom(ranstate); + drmSLInsert(list, keys[i], NULL); + } + + previous = 0; + if (drmSLFirst(list, &key, &value)) { + do { + if (key <= previous) { + printf( "%lu !< %lu\n", previous, key); + } + previous = key; + } while (drmSLNext(list, &key, &value)); + } + + gettimeofday(&start, NULL); + for (j = 0; j < iter; j++) { + for (i = 0; i < size; i++) { + if (drmSLLookup(list, keys[i], &value)) + printf("Error %lu %d\n", keys[i], i); + } + } + gettimeofday(&stop, NULL); + + usec = (double)(stop.tv_sec * 1000000 + stop.tv_usec + - start.tv_sec * 1000000 - start.tv_usec) / (size * iter); + + printf("%0.2f microseconds for list length %d\n", usec, size); + + drmRandomDouble(ranstate); + drmSLDestroy(list); + + return usec; +} + +static void print_neighbors(void *list, unsigned long key) +{ + unsigned long prev_key = 0; + unsigned long next_key = 0; + void *prev_value; + void *next_value; + int retval; + + retval = drmSLLookupNeighbors(list, key, + &prev_key, &prev_value, + &next_key, &next_value); + printf("Neighbors of %5lu: %d %5lu %5lu\n", + key, retval, prev_key, next_key); +} + +int main(void) +{ + void* list; + double usec, usec2, usec3, usec4; + + list = drmSLCreate(); + printf( "list at %p\n", list); + + print(list); + printf("\n==============================\n\n"); + + drmSLInsert(list, 123, NULL); + drmSLInsert(list, 213, NULL); + drmSLInsert(list, 50, NULL); + print(list); + printf("\n==============================\n\n"); + + print_neighbors(list, 0); + print_neighbors(list, 50); + print_neighbors(list, 51); + print_neighbors(list, 123); + print_neighbors(list, 200); + print_neighbors(list, 213); + print_neighbors(list, 256); + printf("\n==============================\n\n"); + + drmSLDelete(list, 50); + print(list); + printf("\n==============================\n\n"); + + drmSLDump(list); + drmSLDestroy(list); + printf("\n==============================\n\n"); + + usec = do_time(100, 10000); + usec2 = do_time(1000, 500); + printf("Table size increased by %0.2f, search time increased by %0.2f\n", + 1000.0/100.0, usec2 / usec); + + usec3 = do_time(10000, 50); + printf("Table size increased by %0.2f, search time increased by %0.2f\n", + 10000.0/100.0, usec3 / usec); + + usec4 = do_time(100000, 4); + printf("Table size increased by %0.2f, search time increased by %0.2f\n", + 100000.0/100.0, usec4 / usec); + + return 0; +}