Skip to content

performance issue #1

@arist1213

Description

@arist1213

This is my local test, which data_x represents how much megabits to be encrypt.
I generated from 1 to 100 megabits to data directory, below is some test results. It's used huge memory and time to encrypt data.

test tools
https://github.com/Svish/TimerPHP
/my/path/to/test_xxtea/test_xxtea.php()

│ 78.502 s
│ 6.58 KiB, 1.14 GiB

├ test_encrypt()
│ │
│ │ 78.502 s
│ │ 5.86 KiB, 1.14 GiB
│ │
│ ├ test_encrypt(data/data_10)
│ │ │
│ │ │ 12.831 s
│ │ │ 1.44 KiB, 855.50 MiB
│ │ ─┘
│ │
│ ├ test_encrypt(data/data_11)
│ │ │
│ │ │ 14.563 s
│ │ │ 160.00 B, 934.50 MiB
│ │ ─┘
│ │
│ ├ test_encrypt(data/data_12)
│ │ │
│ │ │ 15.647 s
│ │ │ 144.00 B, 1013.50 MiB
│ │ ─┘
│ │
│ ├ test_encrypt(data/data_13)
│ │ │
│ │ │ 16.984 s
│ │ │ 144.00 B, 1.07 GiB
│ │ ─┘
│ │
│ ├ test_encrypt(data/data_14)
│ │ │
│ │ │ 18.477 s
│ │ │ 144.00 B, 1.14 GiB
│ │ ─┘
│ ─┘

test_xxtea_script.php

<?php
include 'Xxtea.class.php';
include 'Timer.php';

function p($message = '', $tag = 'debug') {
    echo '['. $tag .']'. " ". $message ."\n";
}

function generateData($meta=1)
{
    // 1024
    $str = str_repeat(str_repeat('y', pow(2, 10)), $meta*1024);
    $file_name = 'data/data_'.$meta;
    file_put_contents($file_name, $str);
    p("generate ".$meta." M data to ".$file_name, 'generate data');
    unset($str);
}

function test_encrypt($start, $end) 
{
    Timer::start('test_encrypt');
    for($i = $start; $i < $end; $i++)
    {        
        $file_name = "data/data_".$i;
        p($file_name, 'before encrypt');
        Timer::start("test_encrypt", [$file_name]);      
        $encrypt_data = null;    
        if (file_exists($file_name))
        {
            $encrypt_data = xxtea_encrypt(file_get_contents($file_name));
            file_put_contents("data_enrypt/data_".$i."_enrypted", $encrypt_data);
        }
        unset($encrypt_data);
        p($file_name, 'after encrypt');
        // Sub section stuff
        Timer::stop();
    }
}
$start = 10;
$end = 15;
Timer::start($_SERVER['PHP_SELF']);
test_encrypt($start, $end);
Timer::stop();
echo $result = Timer::result();
file_put_contents("result_".$start."_".$end.".txt", $result);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions