PHPackages                             nonetallt/joptimize - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nonetallt/joptimize

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nonetallt/joptimize
===================

Automatically optimize PHP methods based on results achieved by tweaking parameters

016PHP

Since Jan 2Pushed 8y agoCompare

[ Source](https://github.com/nonetallt/joptimize)[ Packagist](https://packagist.org/packages/nonetallt/joptimize)[ RSS](/packages/nonetallt-joptimize/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

joptimize
=========

[](#joptimize)

Automatically optimize PHP execution time based on results achieved by tweaking parameters. Can be integrated to a Laravel framework application with the [Laravel wrapper](https://github.com/nonetallt/joptimize-laravel).

Installation
============

[](#installation)

```
composer require nonetallt/joptimize --dev

```

Basic usage
===========

[](#basic-usage)

```
$optimizer = new Joptimize();
$optimizer->defineEnum('sleepTime', 1000, 2000, 3000, 4000);
$result = $optimizer->optimize(function($params) {
    usleep($params->sleepTime);
});

// Will return ['sleepTime' => 1000]
```

Supported parameter types
=========================

[](#supported-parameter-types)

**Enum** : test a group of values and find the fastest value

```
$optimizer->defineEnum($name, ...$values);
```

---

**Linear** : test a all values from start to end and find the fastest value

```
$optimizer->defineLinear($name, $start, $end, $stepSize = 1);
```

---

**Range** : close towards the fastest value in the range, increasing the number of iterations will improve accuracy but take more executions to calculate

```
$optimizer->defineRange($name, $min, $max, $maxIterations);
```

Initialization
==============

[](#initialization)

You can pass a keyed array to the constructor to use values in the array in context of the closure without having to recalculate values on each iteration. This can be useful when there are many values that will make use() definition messy.

```
$optimizer = new Joptimize(['example' => 1]);
$optimizer->defineEnum('sleepTime', 1000, 2000, 3000, 4000);
$result = $optimizer->optimize(function($params, $iteration, $init) {
    echo $init->example;
    // 1
});
```

Logging progress using the notifier callbacks
=============================================

[](#logging-progress-using-the-notifier-callbacks)

Starting and completing of iterations can be tracked by using the following notifier methods:

- onFirstIteration($callback) called before executing the first iteration
- onIterationStart($callback) called before each iteration
- onIterationEnd($callback) called after each iteration
- onLastIteration($callback) called after last iteration

```
$optimizer = new Joptimize();
$optimizer->defineEnum('sleepTime', 1);
$optimizer->onFirstIteration(function($info) {
    echo $info->value; // 123
    echo $info->name; // 'sleepTime'
});
```

---

The first argument passed to the notifier callback is the 'info' object, which contains information accessible in the iteration. All of the info variables might not be usable in all of the notify methods, for example, you cannot use the 'time' variable to log the execution time if the iteration has not been executed yet (onFirst and onStart methods).

MethodnameiterationtotalIterationsvaluebestValuetimebestTimeonFirstIterationxxxx---onIterationStartxxxx---onIterationEndxxxxxxxonLastIterationxxxxxxx---

You may also save custom objects to the info container by calling the saveValue($name, $value) method. This can be useful if you wish to use some variables inside multiple notifier callbacks. For example, you could define your log class variable in the first iteration, and use the log variable in other notifier callbacks.

```
$optimizer = new Joptimize();
$optimizer->defineEnum('sleepTime', 1);

$optimizer->onFirstIteration(function($info) {
    $info->saveValue('logger', new Logger());
});

$optimizer->onIterationStart(function($info) {
    $logger = $info->logger;
    $logger->log("{$info->value}");
});
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/022935c18503b8dff233563d6791746f4a0d7fee43977a1c9f2664806dea632b?d=identicon)[nonetallt](/maintainers/nonetallt)

---

Top Contributors

[![nonetallt](https://avatars.githubusercontent.com/u/22174322?v=4)](https://github.com/nonetallt "nonetallt (16 commits)")

### Embed Badge

![Health badge](/badges/nonetallt-joptimize/health.svg)

```
[![Health](https://phpackages.com/badges/nonetallt-joptimize/health.svg)](https://phpackages.com/packages/nonetallt-joptimize)
```

###  Alternatives

[bumbummen99/shoppingcart

Laravel Shoppingcart

518555.4k3](/packages/bumbummen99-shoppingcart)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
