<commit_before>package html4k.consumers

import html4k.Entities
import html4k.Tag
import html4k.TagConsumer
import java.util.Date

private class MeasureConsumer<R>(val downstream : TagConsumer<R>) : TagConsumer<Pair<R, Long>> {
    private val start = Date()

    override fun onTagStart(tag: Tag) {
        downstream.onTagStart(tag)
    }

    override fun onTagAttributeChange(tag: Tag, attribute: String, value: String) {
        downstream.onTagAttributeChange(tag, attribute, value)
    }

    override fun onTagEnd(tag: Tag) {
        downstream.onTagEnd(tag)
    }

    override fun onTagContent(content: CharSequence) {
        downstream.onTagContent(content)
    }

    override fun onTagContentEntity(entity: Entities) {
        downstream.onTagContentEntity(entity)
    }

    override fun onCDATA(content: CharSequence) {
        downstream.onCDATA(content)
    }

    override fun finalize(): Pair<R, Long> = Pair(downstream.finalize(), (Date().getTime() - start.getTime()).toLong())
}

public fun <R> TagConsumer<R>.measureTime() : TagConsumer<Pair<R, Long>> = MeasureConsumer(this)<commit_msg>Measure time interceptor<commit_after>package html4k.consumers

import html4k.Entities
import html4k.Tag
import html4k.TagConsumer
import java.util.Date

private class MeasureConsumer<R>(val downstream : TagConsumer<R>) : TagConsumer<Pair<R, Long>> {
    private val start = Date()

    override fun onTagStart(tag: Tag) {
        downstream.onTagStart(tag)
    }

    override fun onTagAttributeChange(tag: Tag, attribute: String, value: String) {
        downstream.onTagAttributeChange(tag, attribute, value)
    }

    override fun onTagEnd(tag: Tag) {
        downstream.onTagEnd(tag)
    }

    override fun onTagContent(content: CharSequence) {
        downstream.onTagContent(content)
    }

    override fun onTagContentEntity(entity: Entities) {
        downstream.onTagContentEntity(entity)
    }

    override fun onCDATA(content: CharSequence) {
        downstream.onCDATA(content)
    }

    override fun finalize(): Pair<R, Long> = Pair(downstream.finalize(), Date().getTime().toLong() - start.getTime())
}

public fun <R> TagConsumer<R>.measureTime() : TagConsumer<Pair<R, Long>> = MeasureConsumer(this)
{'fraction_non_alphanumeric': 0.11036339165545088, 'fraction_numerical': 0.003589053387169134, 'mean_word_length': 3.9445676274944566, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1678986', 'n_tokens_mistral': 691, 'n_tokens_neox': 663, 'n_words': 145}