mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.2 UUID
This commit is contained in:
parent
ef466db4c3
commit
eb9557448e
@ -96,18 +96,19 @@ Serial.println(uuid.toCharArray());
|
||||
|
||||
Not tested ESP32 (and many other platforms) yet.
|
||||
|
||||
Performance measured with **UUID_test.ino** shows the following times,
|
||||
Note that 0.1.1 has substantial better performance on AVR.
|
||||
Performance measured with **UUID_test.ino** shows the following times:
|
||||
|
||||
|
||||
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|
||||
|:-------:|:-------------|:------------:|:---------------:|
|
||||
| 0.1.0 | seed | 4 us | |
|
||||
| 0.1.0 | generate | 412 us | |
|
||||
| 0.1.0 | toCharArray | 4 us | |
|
||||
| 0.1.1 | seed | 4 us | |
|
||||
| 0.1.1 | generate | 248 us | |
|
||||
| 0.1.1 | toCharArray | 4 us | |
|
||||
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|
||||
|:-------:|:------------|:----------:|:-------------:|
|
||||
| 0.1.0 | seed | 4 us | |
|
||||
| 0.1.0 | generate | 412 us | |
|
||||
| 0.1.0 | toCharArray | 4 us | |
|
||||
| 0.1.1 | seed | 4 us | |
|
||||
| 0.1.1 | generate | 248 us | |
|
||||
| 0.1.1 | toCharArray | 4 us | |
|
||||
| 0.1.2 | generate | 156 us | |
|
||||
|
||||
|
||||
|
||||
UUID's per second
|
||||
@ -116,6 +117,8 @@ UUID's per second
|
||||
|:-------:|:------------:|:---------------:|:------:|
|
||||
| 0.1.0 | 2000++ | |
|
||||
| 0.1.1 | 4000++ | | generate both modes
|
||||
| 0.1.2 | 6400++ | | generate both modes
|
||||
|
||||
|
||||
Note that this maximum is not realistic e.g. for a server where also
|
||||
other tasks need to be done (listening, transfer etc).
|
||||
@ -136,6 +139,7 @@ See examples.
|
||||
- test other platforms
|
||||
- investigate entropy harvesting
|
||||
- freeRAM, micros, timers, RAM, USB-ID, ...
|
||||
- compile constants __DATE__ and __TIME__
|
||||
- GUID as derived class?
|
||||
- (further identical?)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: UUID.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.2
|
||||
// DATE: 2022-06-14
|
||||
// PURPOSE: Arduino Library for generating UUID's
|
||||
// URL: https://github.com/RobTillaart/UUID
|
||||
@ -14,7 +14,8 @@
|
||||
// fix bug in generator
|
||||
// define UUID_MODE_VARIANT4
|
||||
// define UUID_MODE_RANDOM
|
||||
|
||||
// 0.1.2 2022-06-16 fix version number
|
||||
// improve performance generate()
|
||||
|
||||
|
||||
#include "UUID.h"
|
||||
@ -38,6 +39,7 @@ void UUID::seed(uint32_t s1, uint32_t s2)
|
||||
}
|
||||
|
||||
|
||||
// check version 0.1.1 for more readable code
|
||||
void UUID::generate()
|
||||
{
|
||||
uint32_t _ar[4];
|
||||
@ -57,20 +59,24 @@ void UUID::generate()
|
||||
|
||||
// store globally ?
|
||||
|
||||
|
||||
// build up the char array.
|
||||
for (uint8_t i = 0, j = 0; i < 32; i++, j++)
|
||||
// process 16 bytes build up the char array.
|
||||
for (uint8_t i = 0, j = 0; i < 16; i++)
|
||||
{
|
||||
if (i == 8) _buffer[j++] = '-';
|
||||
else if (i == 12) _buffer[j++] = '-';
|
||||
else if (i == 16) _buffer[j++] = '-';
|
||||
else if (i == 20) _buffer[j++] = '-';
|
||||
// multiples of 4 between 8 and 20 get a -.
|
||||
// but note we are doing 2 digits in one loop.
|
||||
if ((i & 0x1) == 0)
|
||||
{
|
||||
if ((4 <= i) && (i <= 10)) _buffer[j++] = '-';
|
||||
}
|
||||
|
||||
uint8_t nr = i / 8;
|
||||
// process one byte at the time instead of a nibble
|
||||
uint8_t nr = i / 4;
|
||||
uint8_t ch = _ar[nr] & 0xF;
|
||||
_ar[nr] >>= 4;
|
||||
|
||||
_buffer[j] = (ch < 10) ? '0' + ch : ('a' - 10) + ch;
|
||||
_buffer[j++] = (ch < 10) ? '0' + ch : ('a' - 10) + ch;
|
||||
|
||||
ch = (_ar[nr] >> 4) & 0xF;
|
||||
_buffer[j++] = (ch < 10) ? '0' + ch : ('a' - 10) + ch;
|
||||
_ar[nr] >>= 8;
|
||||
}
|
||||
_buffer[36] = 0;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: UUID.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// DATE: 2022-06-14
|
||||
// PURPOSE: Arduino Library for generating UUID's
|
||||
// URL: https://github.com/RobTillaart/UUID
|
||||
@ -15,7 +15,7 @@
|
||||
#include "Printable.h"
|
||||
|
||||
|
||||
#define UUID_LIB_VERSION (F("0.1.1"))
|
||||
#define UUID_LIB_VERSION (F("0.1.2"))
|
||||
|
||||
// TODO an enum?
|
||||
#define UUID_MODE_VARIANT4 0
|
||||
@ -38,6 +38,7 @@ public:
|
||||
// make a UUID string
|
||||
char * toCharArray();
|
||||
|
||||
// MODE
|
||||
void setVariant4Mode() { _mode = UUID_MODE_VARIANT4; };
|
||||
void setRandomMode() { _mode = UUID_MODE_RANDOM; };
|
||||
uint8_t getMode() { return _mode; };
|
||||
|
11
libraries/UUID/examples/UUID_test/output_0.1.1.txt
Normal file
11
libraries/UUID/examples/UUID_test/output_0.1.1.txt
Normal file
@ -0,0 +1,11 @@
|
||||
UUID_test.ino
|
||||
UUID_LIB_VERSION: 0.1.1
|
||||
seed: 8
|
||||
generate: 244
|
||||
toCharArray: 4
|
||||
UUID: 0ac82d02-002b-4ccb-b96c-1c7839cbc4c0
|
||||
UUID: d7652208-bd86-400d-93eb-eeafc12fe18d
|
||||
UUID: cf48f771-f39b-4fdd-a324-acad1c7ac596
|
||||
UUID: f74404e9-3cf4-4769-8c15-1a278e126987
|
||||
UUID: 4fe109d9-09d6-41e0-885a-b4ee716d1f5d
|
||||
|
12
libraries/UUID/examples/UUID_test/output_0.1.2.txt
Normal file
12
libraries/UUID/examples/UUID_test/output_0.1.2.txt
Normal file
@ -0,0 +1,12 @@
|
||||
UUID_test.ino
|
||||
UUID_LIB_VERSION: 0.1.2
|
||||
seed: 4
|
||||
generate: 156
|
||||
toCharArray: 4
|
||||
UUID: 0ac82d02-002b-4ccb-b96c-1c7839cbc4c0
|
||||
UUID: d7652208-bd86-400d-93eb-eeafc12fe18d
|
||||
UUID: cf48f771-f39b-4fdd-a324-acad1c7ac596
|
||||
UUID: f74404e9-3cf4-4769-8c15-1a278e126987
|
||||
UUID: 4fe109d9-09d6-41e0-885a-b4ee716d1f5d
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/UUID.git"
|
||||
},
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=UUID
|
||||
version=0.1.1
|
||||
version=0.1.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for generating UUID's. (experimental).
|
||||
|
Loading…
x
Reference in New Issue
Block a user