Skip to content

Conversation

primo-ppcg
Copy link
Contributor

Filling a lexical gap, to avoid things like this:

(buffer (string/from-bytes ;data))
(buffer/push-byte @"" ;data)

or even this:

(def buf @"")
(each b data
  (buffer/push-byte buf b))

Adding this function has increased the size of the executable by 32 bytes on my system:
master:

$ du -b `which janet`
801384	/usr/local/bin/janet

branch:

$ du -b `which janet`
801416	/usr/local/bin/janet

Of course, it's also faster than either alternative:

(use spork/test)

(var data (range 65 91))

(timeit-loop [:timeout 1]
  (buffer/from-bytes ;data))

(timeit-loop [:timeout 1]
  (buffer (string/from-bytes ;data)))

(timeit-loop [:timeout 1]
  (buffer/push-byte @"" ;data))
buffer/from-bytes 1.000s, 0.1529µs/body
string/from-bytes 1.000s, 0.2261µs/body
buffer/push-byte  1.000s, 0.2637µs/body

@sogaiu
Copy link
Contributor

sogaiu commented Aug 18, 2023

Here's what I got:

$ JANET_PATH=~/src/spork/jpm_tree/lib ~/src/janet.primo-ppcg/build/janet ~/scratch/buffer-from-bytes.janet 
Elapsed time: 1.000s, 0.2079µs/body
Elapsed time: 1.001s, 0.2947µs/body
Elapsed time: 1.000s, 0.3522µs/body

Copy link
Member

@pepe pepe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bakpakin bakpakin merged commit f3969b6 into janet-lang:master Aug 18, 2023
@primo-ppcg primo-ppcg deleted the buffer-from-bytes branch August 18, 2023 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants