Skip to content

armgit / janas

Public Imported from GitHub
0

37 tok/s from Qwen3-Next-80B (48 GB) on a 32 GB laptop, 24 without drafts vs 2.8 for llama.cpp; reading 62 vs 16 tok/s. Faster than llama.cpp on all 13 models compared in Q4_K_M. LLMs bigger than your RAM, pure C, CPU or GPU.

3.4 KB
Raw Blame
/* SPDX-License-Identifier: GPL-3.0-or-later
   Copyright (C) 2026 Maurizio Cammalleri */
/*
 * test_deflate.c - deflate.c's sizes against those Python's zlib gives
 * for the same bytes (zlib.compress at its default level): texts, loops,
 * UTF-8, and generated bytes up to a window over several blocks.
 */
#include "common/deflate.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static const struct {
    const char *s;
    long size;
} TEXTS[] = {
    {"", 8},
    {"a", 9},
    {"ab", 10},
    {"abc", 11},
    {"Thank you. Thank you. Thank you. Thank you. Thank you. Thank you.", 22},
    {" And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country.",
     79},
    {" Buongiorno a tutti. Oggi parliamo di come funziona un motore di inferenza per i modelli linguistici.",
     87},
    {"la la la la la la la la la la la la la la la la la la la la la la la la la la la la",
     14},
    {"\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf\xe4\xb8\x96\xe7\x95\x8c",
     32},
    {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
     12},
    {"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. ",
     57},
    {"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
     23},
};

static const struct {
    unsigned long long seed;
    size_t n;
    const char *alpha;
    size_t na;
    long size;
} GEN[] = {
    {1, 700, "abc ", 4, 260},  {2, 5000, NULL, 256, 5011},
    {3, 20000, "ab", 2, 3254}, {4, 32000, "abcdefghij ", 11, 16617},
    {5, 1000, "x", 1, 17},     {6, 17000, NULL, 256, 17016},
};

int main(void)
{
    int bad = 0;
    for (size_t i = 0; i < sizeof TEXTS / sizeof *TEXTS; i++) {
        long z =
            janas_deflate_size((const uint8_t *)TEXTS[i].s, strlen(TEXTS[i].s));
        if (z != TEXTS[i].size) {
            fprintf(stderr, "test_deflate: text %zu: %ld bytes, zlib %ld\n", i,
                    z, TEXTS[i].size);
            bad++;
        }
    }
    for (size_t i = 0; i < sizeof GEN / sizeof *GEN; i++) {
        uint8_t *b = malloc(GEN[i].n);
        if (!b)
            return 1;
        unsigned long long s = GEN[i].seed;
        for (size_t k = 0; k < GEN[i].n; k++) {
            s ^= s << 13;
            s ^= s >> 7;
            s ^= s << 17;
            unsigned v = (unsigned)((s >> 32) % GEN[i].na);
            b[k] = GEN[i].alpha ? (uint8_t)GEN[i].alpha[v] : (uint8_t)v;
        }
        long z = janas_deflate_size(b, GEN[i].n);
        if (z != GEN[i].size) {
            fprintf(stderr,
                    "test_deflate: generated %zu: %ld bytes, zlib %ld\n", i, z,
                    GEN[i].size);
            bad++;
        }
        free(b);
    }
    if (bad)
        return 1;
    printf(
        "test_deflate: ok (%zu texts, %zu generated, the sizes zlib gives)\n",
        sizeof TEXTS / sizeof *TEXTS, sizeof GEN / sizeof *GEN);
    return 0;
}