.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Data::StreamSerializer 3pm" .TH Data::StreamSerializer 3pm "2011-03-02" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Data::StreamSerializer \- non\-blocking serializer. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Data::StreamSerializer; \& \& my $sr = new Data::StreamSerializer(\*(AqYou data\*(Aq); \& \& while(defined(my $part = $sr\->next)) { \& print $socket $part; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Sometimes You need to serialize a lot of data. If You use 'Dumper' it can take You for much time. If Your code is executed in event machine it can be inadmissible. So using the module You can serialize Your data progressively and do something between serialization itearions. .PP This module works slower than Data::Dumper, but it can serialize object progressively and You can do something else between serialization iterations. .SS "Recognized types." .IX Subsection "Recognized types." \fI\s-1HASH\s0\fR .IX Subsection "HASH" .PP \fI\s-1ARRAY\s0\fR .IX Subsection "ARRAY" .PP \fI\s-1REF\s0\fR .IX Subsection "REF" .PP \fIRegexp\fR .IX Subsection "Regexp" .PP \fI\s-1SCALAR\s0\fR .IX Subsection "SCALAR" .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Constructor. All arguments will be serialized. .SS "next" .IX Subsection "next" Returns next part of serialized string or \fBundef\fR if all data were serialized. .SS "block_size" .IX Subsection "block_size" Block size for one iteration. Too small value allows You to spend less time for each iteration, but in this case total serialization time will grow. Nod bad choice to set the value between 200 \- 2000 bytes (default value is 512). See \s-1BENCHMARKS\s0 to make a decision. .SS "recursion_depth" .IX Subsection "recursion_depth" If serialized object has recursive references, they will be replaced by empty objects. But if this value is higher than 1 recursion will be reserialized until the value is reached. .PP Example: .PP .Vb 2 \& my $t = { a => \*(Aqb\*(Aq }; \& $t\->{c} = $t; .Ve .PP This example will be serialized into string: .PP .Vb 1 \& {"c",{"c",{},"a","b"},"a","b"} .Ve .PP and if You increment recursion_depth, this example will be serialized into string: {\*(L"c\*(R",{\*(L"c\*(R",{\*(L"c\*(R",{},\*(L"a\*(R",\*(L"b\*(R"},\*(L"a\*(R",\*(L"b\*(R"},\*(L"a\*(R",\*(L"b\*(R"} .PP etc. .SS "recursion_detected" .IX Subsection "recursion_detected" Returns \fB\s-1TRUE\s0\fR if a recursion was detected. .SS "is_eof" .IX Subsection "is_eof" Returns \fB\s-1TRUE\s0\fR if eof is reached. If it is \fB\s-1TRUE\s0\fR the following next will return \fBundef\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" Data::StreamDeserializer. .SH "BENCHMARKS" .IX Header "BENCHMARKS" You can try a few scripts in \fBbenchmark/\fR directory. There are a few test arrays in this directory. .PP Here are a few test results of my system. .SS "Array which contains 100 hashes:" .IX Subsection "Array which contains 100 hashes:" .Vb 6 \& $ perl benchmark/vs_dumper.pl \-n 1000 \-b 512 benchmark/tests/01_100x10 \& 38296 bytes were read \& First serializing by eval... done \& First serializing by Data::StreamSerializer... done \& Starting 1000 iterations for Dumper... done (40.376 seconds) \& Starting 1000 iterations for Data::StreamSerializer... done (137.960 seconds) \& \& Dumper statistic: \& 1000 iterations were done \& maximum serialization time: 0.0867 seconds \& minimum serialization time: 0.0396 seconds \& average serialization time: 0.0404 seconds \& \& Data::StreamSerializer statistic: \& 1000 iterations were done \& 58000 SUBiterations were done \& maximum serialization time: 0.1585 seconds \& minimum serialization time: 0.1356 seconds \& average serialization time: 0.1380 seconds \& average subiteration time: 0.00238 seconds .Ve .SS "Array which contains 1000 hashes:" .IX Subsection "Array which contains 1000 hashes:" .Vb 6 \& $ perl benchmark/vs_dumper.pl \-n 1000 \-b 512 benchmark/tests/02_1000x10 \& 355623 bytes were read \& First serializing by eval... done \& First serializing by Data::StreamSerializer... done \& Starting 1000 iterations for Dumper... done (405.334 seconds) \& Starting 1000 iterations for Data::StreamSerializer... done (1407.899 seconds) \& \& Dumper statistic: \& 1000 iterations were done \& maximum serialization time: 0.4564 seconds \& minimum serialization time: 0.4018 seconds \& average serialization time: 0.4053 seconds \& \& Data::StreamSerializer statistic: \& 1000 iterations were done \& 520000 SUBiterations were done \& maximum serialization time: 2.0050 seconds \& minimum serialization time: 1.3862 seconds \& average serialization time: 1.4079 seconds \& average subiteration time: 0.00271 seconds .Ve .PP You can see that in any cases one iteration gets the same time. .SH "AUTHOR" .IX Header "AUTHOR" Dmitry E. Oboukhov, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2011 by Dmitry E. Oboukhov .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. .SH "VCS" .IX Header "VCS" The project is placed in my git repo. See here: