{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8ae0ea81", "metadata": {}, "outputs": [], "source": [ "from json_ntv import Ntv, NtvSingle, NtvList\n", "from namespace import Namespace, Datatype\n", "from time import time\n", "\n", "def ntvobj(nb=1000, lis=True, jname='', jdefname=''):\n", " if jdefname and lis:\n", " return {jdefname: [{str(i) + jname : i} for i in range(nb)]}\n", " if jdefname and not lis:\n", " return {jdefname: {str(i) + jname : i for i in range(nb)}}\n", " if lis:\n", " return [{str(i) + jname : i} for i in range(nb)]\n", " return {str(i) + jname : i for i in range(nb)}\n", "\n", "def ntvl(nb=1000, json_array=True, jname='', deftyp=None, obj=None, fast=False, direct=False):\n", " t0 = time()\n", " if obj:\n", " ntv = Ntv.obj(obj)\n", " else:\n", " if jname and not direct:\n", " ntv = NtvList([Ntv.from_obj({str(i) + jname : i}, deftyp) for i in range(nb)], fast=fast)\n", " elif not direct:\n", " ntv = NtvList([Ntv.from_obj({str(i) : i}, deftyp) for i in range(nb)], fast=fast) \n", " else:\n", " ntv = NtvList([NtvSingle(i, str(i), deftyp, fast=fast) for i in range(nb)], fast=fast) \n", " t1 = time()\n", " js = ntv.to_obj(json_array=json_array)\n", " t2 = time()\n", " return (t1-t0, t2-t1)" ] }, { "cell_type": "code", "execution_count": 2, "id": "6c646e99", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'::int': {'0:int': 0, '1:int': 1, '2:int': 2}}\n", "{\"::int\": {\"0\": 0, \"1\": 1, \"2\": 2}}\n", "(0.0, 0.0)\n" ] } ], "source": [ "print(ntvobj(3, False, ':int', '::int'))\n", "print(Ntv.obj(ntvobj(3, False, ':int', '::int')))\n", "print(ntvl(obj=ntvobj(3, False, ':int', '::int')))" ] }, { "cell_type": "code", "execution_count": 3, "id": "469bb0bd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(0.22454524040222168, 0.0806572437286377)\n", "(0.19915413856506348, 0.039829254150390625)\n", "(0.21956729888916016, 0.03883481025695801)\n", "(0.26154494285583496, 0.047797203063964844)\n", "(0.36594581604003906, 0.03883481025695801)\n", "(0.20214152336120605, 0.039331912994384766)\n", "(0.4665186405181885, 0.03883504867553711)\n", "(0.2001497745513916, 0.046303510665893555)\n", "(0.3759043216705322, 0.09360146522521973)\n", "(0.20712018013000488, 0.04082798957824707) \n", "\n", "(0.2444610595703125, 0.04530787467956543)\n", "(0.2743351459503174, 0.05924844741821289)\n", "(0.30669617652893066, 0.04580521583557129)\n", "(0.1986539363861084, 0.04288005828857422)\n", "(0.3654487133026123, 0.10117268562316895)\n", "(0.22056317329406738, 0.03983116149902344)\n", "(0.3694310188293457, 0.04580545425415039)\n", "(0.2001500129699707, 0.0952303409576416)\n", "(0.36550331115722656, 0.050286054611206055)\n", "(0.2215588092803955, 0.04829525947570801) \n", "\n" ] } ], "source": [ "nb = 10000\n", "\n", "for cl in (True, False):\n", " if cl:\n", " print(ntvl(nb, cl))\n", " print(ntvl(obj=ntvobj(nb, cl)))\n", " else:\n", " print(ntvl(nb, cl, 'test'))\n", " print(ntvl(obj=ntvobj(nb, cl, 'test')))\n", " print(ntvl(nb, cl, ':int'))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int')))\n", " print(ntvl(nb, cl, ':int', 'int'))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::int')))\n", " print(ntvl(nb, cl, ':int', 'json'))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::json')))\n", " print(ntvl(nb, cl, ':int', 'point'))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::point')), '\\n')\n", "#print(Datatype.types())" ] }, { "cell_type": "code", "execution_count": 4, "id": "f377e4ff", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(0.2864339351654053, 0.0403285026550293)\n", "(0.22504568099975586, 0.04231858253479004)\n", "(0.2096095085144043, 0.03833723068237305)\n", "(0.21110272407531738, 0.0403287410736084)\n", "(0.3639554977416992, 0.03335690498352051)\n", "(0.25896120071411133, 0.04630255699157715)\n", "(0.39432573318481445, 0.0403294563293457)\n", "(0.2554147243499756, 0.05028676986694336)\n", "(0.391340970993042, 0.03684258460998535)\n", "(0.20413589477539062, 0.04232001304626465) \n", "\n", "(0.2793147563934326, 0.03335762023925781)\n", "(0.23798847198486328, 0.03933119773864746)\n", "(0.267366886138916, 0.03534889221191406)\n", "(0.21010828018188477, 0.03933358192443848)\n", "(0.39681410789489746, 0.03286027908325195)\n", "(0.2857849597930908, 0.04929208755493164)\n", "(0.3773972988128662, 0.04082679748535156)\n", "(0.2041308879852295, 0.04132533073425293)\n", "(0.44112539291381836, 0.03335833549499512)\n", "(0.20761823654174805, 0.04530835151672363) \n", "\n" ] } ], "source": [ "nb = 10000\n", "fast=True\n", "\n", "for cl in (True, False):\n", " if cl:\n", " print(ntvl(nb, cl, fast=fast))\n", " print(ntvl(obj=ntvobj(nb, cl), fast=fast))\n", " else:\n", " print(ntvl(nb, cl, 'test', fast=fast))\n", " print(ntvl(obj=ntvobj(nb, cl, 'test'), fast=fast))\n", " print(ntvl(nb, cl, ':int', fast=fast))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int'), fast=fast))\n", " print(ntvl(nb, cl, ':int', 'int', fast=fast))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::int'), fast=fast))\n", " print(ntvl(nb, cl, ':int', 'json', fast=fast))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::json'), fast=fast))\n", " print(ntvl(nb, cl, ':int', 'point', fast=fast))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::point'), fast=fast), '\\n')\n", "#print(Datatype.types())" ] }, { "cell_type": "code", "execution_count": 5, "id": "64adf930", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(0.09011650085449219, 0.04132437705993652)\n", "(0.22603988647460938, 0.046801090240478516)\n", "(0.07767009735107422, 0.03335833549499512)\n", "(0.20811724662780762, 0.05128145217895508)\n", "(0.17077422142028809, 0.03385639190673828)\n", "(0.277820348739624, 0.039830684661865234)\n", "(0.17674946784973145, 0.03385615348815918)\n", "(0.2658696174621582, 0.041823387145996094)\n", "(0.17376017570495605, 0.03584790229797363)\n", "(0.22106242179870605, 0.09360122680664062) \n", "\n", "(0.028378725051879883, 0.03335881233215332)\n", "(0.20214128494262695, 0.04580521583557129)\n", "(0.07843446731567383, 0.041324615478515625)\n", "(0.19716286659240723, 0.04530763626098633)\n", "(0.22105932235717773, 0.03335905075073242)\n", "(0.29325366020202637, 0.03983116149902344)\n", "(0.17376208305358887, 0.03385615348815918)\n", "(0.2404782772064209, 0.0941004753112793)\n", "(0.1732649803161621, 0.03335905075073242)\n", "(0.23706865310668945, 0.04132437705993652) \n", "\n" ] } ], "source": [ "nb = 10000\n", "fast=True # fast ntvtype à voir\n", "direct=True\n", "\n", "for cl in (True, False):\n", " if cl:\n", " print(ntvl(nb, cl, fast=fast, direct=direct)) # + rapide\n", " print(ntvl(obj=ntvobj(nb, cl), fast=fast, direct=direct))\n", " else:\n", " print(ntvl(nb, cl, 'test', fast=fast, direct=direct)) # 2e + rapide\n", " print(ntvl(obj=ntvobj(nb, cl, 'test'), fast=fast, direct=direct))\n", " print(ntvl(nb, cl, ':int', fast=fast, direct=direct))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int'), fast=fast, direct=direct))\n", " print(ntvl(nb, cl, ':int', 'int', fast=fast, direct=direct))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::int'), fast=fast, direct=direct))\n", " print(ntvl(nb, cl, ':int', 'json', fast=fast, direct=direct))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::json'), fast=fast, direct=direct))\n", " print(ntvl(nb, cl, ':int', 'point', fast=fast, direct=direct))\n", " print(ntvl(obj=ntvobj(nb, cl, ':int', '::point'), fast=fast, direct=direct), '\\n')\n", "#print(Datatype.types())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" } }, "nbformat": 4, "nbformat_minor": 5 }