Skip to content

Commit

Permalink
Added preformance and removed support for numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
Mortimer333 authored Jan 20, 2021
1 parent 5ce3420 commit 5bd2712
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Xeno
Makes native PHP functions more bearable and useable.

```php

Expand Down Expand Up @@ -33,7 +32,7 @@ To specify using different modes you can, while defining the variable, pass as s
$str = new X(1, X::RETURN); // defining new instance with return mode
$str->mode(X::CHAIN) // changing mode to chain
```
To get variable you can use `get` method, to set it use `set`.
To get a variable - use `get` method and to set it to new value - use `set`.
```php
$array = new X(['a']);
$array->set(['b']); // changing content
Expand Down Expand Up @@ -69,7 +68,6 @@ When you want to create method named the same for all types (ex. cut) then add p
- `str_` - string
- `ary_` - array
- `obj_` - object
- `num_` - numeric (int or float)
- `int_` - only integer
- `dec_` - only float

Expand All @@ -91,7 +89,7 @@ When you want to create method named the same for all types (ex. cut) then add p
[...] // the rest of class
```

Here I have added two methods `str_cut` and `array_cut`. Both of them you can call by `cut` and script will choose right one by its prefix and current value (or none if you call it on non supported type, in this example it would be numeric). Of course you can still call them by their full name but you need to be sure that you are using right values.
Here I have added two methods `str_cut` and `array_cut`. Both of them you can call by `cut` and script will choose right one by its prefix and current value (or none if you call it on non supported type, in this example it would be intiger). Of course you can still call them by their full name but you need to be sure that you are using right values.

```php
$str = new X('Hello world');
Expand All @@ -103,3 +101,28 @@ Here I have added two methods `str_cut` and `array_cut`. Both of them you can ca
$int = new X(1);
echo $int->cut( 1, 2 )->get(); // Fatal error: Uncaught BadMethodCallException: cut
```
# Performance

The performance depends on how you call methods. Using full names of functions is much faster (3~4x) so in a case when you have thousands of operations it's better to call by using functions full names.

### Some numbers (milion iterations):

Full names and native functions :
- ~0.26 s - without new instance of Xeno each iteration
- ~0.35 s - with new instance of Xeno each iteration

Full names and methods :
- ~0.18 s - without new instance of Xeno each iteration
- ~0.21 s - with new instance of Xeno each iteration

Short names and native function :
- ~0.67 s - without new instance of Xeno each iteration
- ~0.83 s - with new instance of Xeno each iteration

Short names and methods :
- ~0.71 s - without new instance of Xeno each iteration
- ~0.81 s - with new instance of Xeno each iteration

# Disclaimer

For some comparison a milion iterations of str_replace on my computer was 0.05 s. That means you shouldn't use this library for any big operations. It's purpose is to enable chain syntax on primitives without installing new packages and having library which will be always updated. If you can install additional stuff on your serwer I recommend https://github.com/nikic/scalar_objects for better syntax on primitives.

0 comments on commit 5bd2712

Please sign in to comment.